by nageswaragunupudi » Sun Jun 21, 2015 2:32 am
Both Harbour and xHarbour have the data type 'T', i.e., DateTime value.
Optimized functions for conversion of Date type to DateTime type and vice-versa are:
FW_TTOD( tDateTime/dDate ) --> dDate ( valtype 'D' )
and
FW_DTOT( dDate ) --> tDateTime( valtype 'T' ) // time is 0 seconds.
To get the timepart of DateTime variable in seconds
FW_TIMEPART( tDateTime ) --> nSeconds
or
SecToTime( FW_TIMEPART( tDateTime ) ) --> cTimePart ( eg. '10:11:12' )
Add ( or Subtract ) Time to Date or DateTime variable --> returns DateTime value
FW_ADDTIME( dDate_or_tDateTime, cTime ) --> tDateTime
Eg: ? FW_ADDTIME( {^ 2010/10/20 }, "2d 10:12:32" ) --> '22-10-2010 10:12:32'
? FW_ADDTIME( {^ 2010/10/20 }, "-2d 10:12:32" ) --> '17-10-2010 13:47:28'
Though the dates are stored in MSSQL table as DateTime Values, we can assign either dDate value of type 'D' or tDateTime value of type 'T'.
oRs:Fields( "DTFIELD" ):Value := Date() // or DateTime()
tValue := oRs:Fields( "DTFIELD" ):Value // returns a tDateTime value of type 'T'
To extract only the truncated date
dValue := FW_TTOD( oRs:Fields( "DTFIELD" ):Value )
When you want to assign empty date it is desirable to assign AdoNull()
eg:
oRs:Fields( "DTFIELD" ):Value := AdoNull() // instead of CtoD( "" )
Note:
Recent versions of SQL Server provides a field type "Date" which stores only a pure date value, without time part. From my experiences, I advise not to use this type, but to depend on DateTime field or SmallDateTime field type
If required I can elaborate the reasons.
Regards
G. N. Rao.
Hyderabad, India