nTimestamp to cDate and cTime
Moderator: Rathinagiri
nTimestamp to cDate and cTime
Hi, I need to convert a timestamp value to date and time in harbor unixtime format
1489364562.247 = 2017-03-13 00:22:42.247 converter Converted web site in php
nValue := 1489364562.247
cDate := ??
Ctime := ??
1489364562.247 = 2017-03-13 00:22:42.247 converter Converted web site in php
nValue := 1489364562.247
cDate := ??
Ctime := ??
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: nTimestamp to cDate and cTime
It is number of seconds from 1st of January of 1970.
We can write a small module to divide the above number by 60, 60, 24 taking only quotients.
Reminders can be multiplied by 60, 60, 24 to find out the seconds, minutes and hours respectively.
We can write a small module to divide the above number by 60, 60, 24 taking only quotients.
Reminders can be multiplied by 60, 60, 24 to find out the seconds, minutes and hours respectively.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: nTimestamp to cDate and cTime
There is no function in harbor to do this, could you give an example of your explanation how can I get the date and the time
Last edited by jairpinho on Mon Mar 13, 2017 5:57 pm, edited 1 time in total.
Re: nTimestamp to cDate and cTime
Rathinagiri wrote: ↑Mon Mar 13, 2017 5:27 pm It is number of seconds from 1st of January of 1970.
We can write a small module to divide the above number by 60, 60, 24 taking only quotients.
Reminders can be multiplied by 60, 60, 24 to find out the seconds, minutes and hours respectively.
There is no function in harbor to do this, could you give an example of your explanation how can I get the date and the time,
I can not return the date yyyymmdd from seconds
Last edited by jairpinho on Tue Mar 14, 2017 4:46 pm, edited 1 time in total.
Re: nTimestamp to cDate and cTime
jairpinho
See in PeteWG's "Harbour functions dictionary": https://github.com/Petewg/V-harbour-core/wiki/hb_T
TimeStamp functions: hb_TSToStr, hb_TSToUTC, hb_TtoC, etc.
See in PeteWG's "Harbour functions dictionary": https://github.com/Petewg/V-harbour-core/wiki/hb_T
TimeStamp functions: hb_TSToStr, hb_TSToUTC, hb_TtoC, etc.
Re: nTimestamp to cDate and cTime
KDJ wrote: ↑Mon Mar 13, 2017 7:20 pm jairpinho
See in PeteWG's "Harbour functions dictionary": https://github.com/Petewg/V-harbour-core/wiki/hb_T
TimeStamp functions: hb_TSToStr, hb_TSToUTC, hb_TtoC, etc.
This is for the format = 2017-03-13 00:22:42.247, My format is decimal in seconds = 1489364562.247
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: nTimestamp to cDate and cTime
Jair,
Check up this:
Check up this:
Code: Select all
#include <hmg.ch>
Function Main
msginfo( getDateTime( 1489364562.247 ) )
Return
function getDateTime( nTime )
set cent on
cMilliSeconds := padl( mod( nTime, 1 ) * 1000, 3, '0' )
nTime := int( nTime )
cSeconds := padl( mod( nTime, 60 ), 2, '0' )
nTime := int( nTime / 60 )
cMinutes := padl( mod( nTime, 60 ), 2, '0' )
nTime := int( nTime / 60 )
cHours := padl( mod( nTime, 24 ), 2, '0' )
nTime := int( nTime / 24 )
dFirstDate := stod( '19700101' )
dDate := dFirstDate + nTime
cYear := padl( year( dDate ), 4, '0' )
cMonth := padl( month( dDate ), 2, '0' )
cDay := padl( day( dDate ), 2, '0' )
// 2017-03-13 00:22:42.247
cReturn := cYear + '-' + cMonth + '-' + cDay + ' ' + cHours + ':' + cMinutes + ':' + cSeconds + '.' + cMilliSeconds
return cReturn
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: nTimestamp to cDate and cTime
Rathinagiri wrote: ↑Tue Mar 14, 2017 6:09 pm Jair,
Check up this:
Code: Select all
#include <hmg.ch> Function Main msginfo( getDateTime( 1489364562.247 ) ) Return function getDateTime( nTime ) set cent on cMilliSeconds := padl( mod( nTime, 1 ) * 1000, 3, '0' ) nTime := int( nTime ) cSeconds := padl( mod( nTime, 60 ), 2, '0' ) nTime := int( nTime / 60 ) cMinutes := padl( mod( nTime, 60 ), 2, '0' ) nTime := int( nTime / 60 ) cHours := padl( mod( nTime, 24 ), 2, '0' ) nTime := int( nTime / 24 ) dFirstDate := stod( '19700101' ) dDate := dFirstDate + nTime cYear := padl( year( dDate ), 4, '0' ) cMonth := padl( month( dDate ), 2, '0' ) cDay := padl( day( dDate ), 2, '0' ) // 2017-03-13 00:22:42.247 cReturn := cYear + '-' + cMonth + '-' + cDay + ' ' + cHours + ':' + cMinutes + ':' + cSeconds + '.' + cMilliSeconds return cReturn
Thank you worked just one detail at the time(cHours), maybe I have to add timezone, so returned
2017-03-13 0.:22:42.247
- Attachments
-
- get_data.gif (51.08 KiB) Viewed 4189 times
Re: nTimestamp to cDate and cTime
Thank you all with the help of the Rathinagiri I made correction changes and it worked perfect
Code: Select all
Function getDateTime( nTime )
set cent on
cMilliSeconds := padl( STRZERO( mod( nTime, 1 )*1000 ,3) , 3, '0' )
nTime := int( nTime )
cSeconds := padl( STRZERO( mod( nTime, 60 ), 2 ), 2, '0' )
nTime := int( nTime / 60 )
cMinutes := padl( STRZERO( mod( nTime, 60 ), 2 ), 2, '0' )
nTime := int( nTime / 60 )
cHours := padl( STRZERO( mod( nTime, 24 ), 2 ) , 2, '0' )
nTime := int( nTime / 24 )
dFirstDate := stod( '19700101' )
dDate := dFirstDate + nTime
cYear := padl( year( dDate ), 4, '0' )
cMonth := padl( month( dDate ), 2, '0' )
cDay := padl( day( dDate ), 2, '0' )
cReturn := cYear + '-' + cMonth + '-' + cDay + ' ' + cHours + ':' + cMinutes + ':' + cSeconds + '.' + cMilliSeconds
Return(cReturn)
Re: nTimestamp to cDate and cTime
This code can be a little shortened:
Code: Select all
FUNCTION Main()
LOCAL nSeconds := 1489364562.247
MsgBox(HB_TStoStr(t"1970-01-01" + nSeconds /60 /60 /24))
RETURN NIL