asp classic - Format a date time string -


im having problem formatting datetime field in asp classic. format need yyyy-mm-dd hh:mm:ss code far:

changetodate = cdate(request.form("datepicker")&" "&request.form("timepicker"))   datetime = datepart("d", changetodate)&"-"&datepart("m", changetodate)&_            "-"&datepart("yyyy", changetodate)&" "&datepart("hh", changetodate)&":"&_            datepart("mi", changetodate)&":00" 

but gives me invalid procedure call datepart exception. i'm kind of stuck on this.

not sure if matters or not doing can insert datetime database. when use cdate function following error:conversion failed when converting date and/or time character string. query looks cdate function called:

insert mytable(client ,campaign ,location ,cardcode ,created ,message ,rating ,info ,mobile ,datamessage ) values (117,227,1487,'njpnuyx','10/07/2013 9:10:00 a.m.','njpnuyx 4 safda',4,'safda','0215833650','0223232345') 

i think you're using incorrect parameters in hour , minute datepart calls.

according msdn need use following:

  • hour - h (instead of hh)
  • minute - n (instead of mi)

change:

datepart("hh", changetodate) & ":" & datepart("mi", changetodate) 

to

datepart("h", changetodate) & ":" & datepart("n", changetodate) 

for more info see http://msdn.microsoft.com/en-us/library/4kt42529%28v=vs.84%29.aspx


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -