How to convert a Date to an Unix TimeStamp?
How to convert a Date to an Unix TimeStamp?
Hi Guys,
How could I convert a date/time to an Unix TimeStamp?
How could I convert a date/time to an Unix TimeStamp?
Re: How to convert a Date to an Unix TimeStamp?
...maybe this ist what you are looking for?
https://forums.fivetechsupport.com/view ... 8b1485830b
kind regards
ruth
https://forums.fivetechsupport.com/view ... 8b1485830b
kind regards
ruth
Re: How to convert a Date to an Unix TimeStamp?
Ruth,
I tried it, but didn´t work here. IF you compare the result with that generated from https://www.timestamp-converter.com/, they aren´t the same.
I tried it, but didn´t work here. IF you compare the result with that generated from https://www.timestamp-converter.com/, they aren´t the same.
- Antonio Linares
- Site Admin
- Posts: 42268
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: How to convert a Date to an Unix TimeStamp?
We have already implemented those functions for FWH already
Please lets wait for Mr. Rao comments about them
Please lets wait for Mr. Rao comments about them
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How to convert a Date to an Unix TimeStamp?
* New functions: (valtostr.prg)
FW_DateToUnix( dDate/tDateTime ) --> nUnixTimeStamp in MilliSeconds
FW_UnixToDate( nUnixTimeStamp(inMilliSeconds) ) --> tDateTime
Please keep in mind that the FWH functions deal with Unix time in MilliSeconds. Not seconds.
Depending on the requirement, you need to provide the conversion ( *1000 or /1000 )
FW_DateToUnix( dDate/tDateTime ) --> nUnixTimeStamp in MilliSeconds
FW_UnixToDate( nUnixTimeStamp(inMilliSeconds) ) --> tDateTime
Code: Select all | Expand
#ifdef __XHARBOUR__
#xtranslate HB_STOT( <c> ) => STOT( <c> )
#xtranslate HB_DateTime() => DateTime()
#endif
//----------------------------------------------------------------------------//
function FW_DateToUnix( tDateTime ) // ( dDate or tDateTime ) --> nMilliSecs
DEFAULT tDateTime := HB_DateTime()
return INT( ( FW_DTOT( tDateTime ) - HB_STOT( "19700101000000" ) ) * 86400000.0 )
//----------------------------------------------------------------------------//
function FW_UnixToDate( nMilliSecs ) // --> tDateTime
if ValType( nMilliSecs ) == "C"
nMilliSecs := Val( nMilliSecs )
else
DEFAULT nMilliSecs := 0
endif
return HB_STOT( "19700101000000" ) + ( nMilliSecs / 86400000.0 )
//----------------------------------------------------------------------------//
Depending on the requirement, you need to provide the conversion ( *1000 or /1000 )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How to convert a Date to an Unix TimeStamp?
If you want to use this functionality with MySql, you can use the MySql built-in functionsvilian wrote:Hi Guys,
How could I convert a date/time to an Unix TimeStamp?
Code: Select all | Expand
UNIX_TIMESTAMP( <datetime> )
FROM_UNIXTIM( nUnixTime )
Please note that FWH functions deal with the UnixTime in millliseconds whereas MySql functions deal with Seconds.
Examples:
Code: Select all | Expand
? oCn:QueryResult( "SELECT UNIX_TIMESTAMP( ? )", { HB_DateTime() } )
? oCn:QueryResult( "SELECT FROM_UNIXTIME( ? , '%d-%m-%Y %H:%i:%S')", { nUnixTimeInSeconds} )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: How to convert a Date to an Unix TimeStamp?
Thank you Mr Rao,
If I try with your function, I'm having this result: 168486480000 for 2023-05-23T18:00:00
But in https://www.timestamp-converter.com/, I'm having a different result(as you can view bellow). Do you know why ?
If I try with your function, I'm having this result: 168486480000 for 2023-05-23T18:00:00
Code: Select all | Expand
SET DATE BRIT
myDate := Hb_Dtot(Ctod("23/05/2023"),"18:00:00")
? FW_DateToUnix( MyDate ) //168486480000
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How to convert a Date to an Unix TimeStamp?
Both are same.
In that website there is an implicit conversion from your time zone to UTC.
Try this code:
Note: UTC_TIMESTAMP() is an FWH function
In that website there is an implicit conversion from your time zone to UTC.
Try this code:
Code: Select all | Expand
? FW_DateToUnix( UTC_TIMESTAMP() )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: How to convert a Date to an Unix TimeStamp?
Thank you, now it's working perfectly