Encode Time Issue in Delphi 2010 -


when use encodetime function encodetime(whour, wminute, wsecond, wmilliseconds) not assigning millisec value result.

we using below encode date , time

result := encodedate(wyear, wmonth, wday) +   encodetime(whour, wminute, wsecond, wmilliseconds); 

the string want parse datetime has value apr 10 2008 7:21:31:460pm after encoding output 10/04/2008 07:21:31.

the result contains hh:mm:ss value , not millisec value.

please let know if there anyway format values , store in variable along millisec. *******************function trying*************

function datetimeparser(thestring :string):tdatetime; var wyear,wmonth,wday,whour, wminute, wsecond,wmilliseconds : word  ; date,month,med :string; time : tdatetime; testtime,testtime1 : tsystemtime; var  mydatetime : tdatetime; begin  month := copy(thestring,1,3) ;  if month ='jan' wmonth := 01      else if  month ='feb'  wmonth := 02      else if  month ='mar'  wmonth := 03      else if  month ='apr'  wmonth := 04      else if  month ='may'  wmonth := 05      else if  month ='jun'  wmonth := 06      else if  month ='jul'  wmonth := 07      else if  month ='aug'  wmonth := 08      else if  month ='sep'  wmonth := 09      else if  month ='oct'  wmonth := 10      else if  month ='nov'  wmonth := 11      else if  month ='dec'  wmonth := 12      else showmessage('not valid month'); wyear           :=  strtoint(copy(thestring,8,4)) ; wday            :=  strtoint(copy(thestring,5,2)) ; whour           :=  strtoint(copy(thestring,13,2)) ; wminute         :=  strtoint(copy(thestring,16,2)) ; wsecond         :=  strtoint(copy(thestring,19,2)) ; wmilliseconds   :=  strtoint(copy(thestring,22,3)) ;  showmessage(inttostr(wmilliseconds));  {if copy(thestring,25,2)= 'pm'  whour := whour+12;}  result := dateutils.encodedatetime(wyear, wmonth, wday,whour, wminute, wsecond, wmilliseconds); //result := result+dateutils.encodetime(whour, wminute, wsecond, wmilliseconds div 100);   mydatetime:= encodedate(2009,11,28)+encodetime(14,23,12,001);  showmessage(datetimetostr(mydatetime)); testtime1 := testtime;   time :=encodetime(whour, wminute, wsecond, wmilliseconds);             showmessage(datetimetostr(result));  **********************************************************************   end; 

any ideas?

i might have misunderstood problem here perhaps getting stored don't see it. debugger not show milliseconds , datetimetostr not either. formatdatetime format string does.

var     date: tdatetime; begin     date := encodedatetime(2011, 02, 28, 20, 43, 10, 12);      //datetimetostr not show milliseconds     showmessage(datetimetostr(date));      //use formatdatetime format string     showmessage(formatdatetime('yyyy-mm-dd hh:nn:ss.zzz' , date)); end; 

database

your dbexpress tag suggests trying store datetime in database. not know dbexpress ado truncates milliseconds out of datetime. to save milliseconds in sql server ado have build insert statement yourself. might same dbexpress.

here ado code save datetime milliseconds in sql server

adocommand1.commandtext := 'insert datetbl values ('''+     formatdatetime('yyyy-mm-dd hh:nn:ss.zzz' , date)+''')'; adocommand1.execute; 

the precision datetime in sql server 3.33 milliseconds. not same in delphi when save 2011-02-28 20:43:10.012 saved 2011-02-28 20:43:10.013 in sql server. might problem you.

one solution store milliseconds part of datetime in separate integer column. way store same value have encoded in delphi , not have build own insert statements.

dbexpress

i have done testing dbx components , truncates milliseconds.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -