Home > Archive > Clipper > December 2004 > Date convert to double ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Date convert to double ?
|
|
| Yannis 2004-12-01, 8:55 am |
| Hi guys,
Anyone knows how to conver the current date and time to a double number?
or at least to a number ?
Best regards
Yannis
elcapitan48[at]yahoo.com
| |
| Dave Pearson 2004-12-01, 8:55 am |
| * Yannis <trentis@kanena.net>:
> Anyone knows how to conver the current date and time to a double number?
> or at least to a number ?
What do you want the number to represent? A number of days from a set date
in the past? What date?
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Ray Marron 2004-12-01, 3:55 pm |
| "Yannis" <trentis@kanena.net> wrote in message
news:cok78r$8eq$1@usenet.otenet.gr...
> Hi guys,
> Anyone knows how to conver the current date and time to a double number?
> or at least to a number ?
Internally, Clipper dates are Julian date integers:
nJulian := dDate - ctod("")
Back to date:
dDate := ctod("") + nJulian
As far as this double, like Dave said, what's your base date?
In Delphi, TDateTime is a double where 1899-12-30 is day 0 (the fractional
part is the time). To convert to a Delphi equivalent integer, you would do:
nDelphiDate := (dDate - StoD('18991230')) - ctod("")
As far as making it a true "double", it depends on what Clipper
implementation you're using and what you're trying to pass it to.
--
Ray Marron
| |
| Dave Pearson 2004-12-01, 3:55 pm |
| * Ray Marron <me@privacy.net>:
> In Delphi, TDateTime is a double where 1899-12-30 is day 0 (the fractional
> part is the time). To convert to a Delphi equivalent integer, you would
> do:
>
> nDelphiDate := (dDate - StoD('18991230')) - ctod("")
Funny you should mention that, I found myself going the other way (Delphi to
Clipper) the other day while hacking around with some xHarbour code:
,----
| Function DelphiDateTimeToDate( nDateTime As Numeric )
| Return( stod( "18991230" ) + int( nDateTime ) )
|
| Function DelphiDateTimeToTime( nDateTime As Numeric )
| Local cTime As String := ""
| Local nSeconds As Numeric
|
| // Work out the number of seconds.
| nSeconds := int( ( 24 * 60 * 60 ) * ( nDateTime - int( nDateTime ) ) )
|
| // Get the hours.
| cTime += padl( int( nSeconds / ( 60 * 60 ) ), 2, "0" ) + ":"
| nSeconds -= int( nSeconds / ( 60 * 60 ) ) * ( 60 * 60 )
|
| // Get minutes.
| cTime += padl( int( nSeconds / 60 ), 2, "0" ) + ":"
| nSeconds -= int( nSeconds / 60 ) * 60
|
| Return( cTime + padl( nSeconds, 2, "0" ) )
`----
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Ray Marron 2004-12-01, 8:55 pm |
| "Dave Pearson" <davep.news@davep.org> wrote in message
news:slrncqrrbd.nkd.davep.news@hagbard.davep.org...
[...]
> Funny you should mention that, I found myself going the other way (Delphi
to
> Clipper) the other day while hacking around with some xHarbour code:
>
> ,----
> | Function DelphiDateTimeToDate( nDateTime As Numeric )
> | Return( stod( "18991230" ) + int( nDateTime ) )
> |
> | Function DelphiDateTimeToTime( nDateTime As Numeric )
> | Local cTime As String := ""
> | Local nSeconds As Numeric
[SNIP]
Must be xHarbour - those function names are too long to be considered
different in CA-Clipper!
One of these days I've got to get around to trying xHarbour. Maybe when I'm
done with all those books I've been meaning to read... :)
--
Ray Marron
| |
| Yannis 2004-12-01, 8:55 pm |
| Thank you guys for the hint !
I can use nJulian + Seconds() to get a unique number (every second),
to use it as part of customer code in a database.
To be sure, i can perform a s just before saving a new customers
record, and if by any chance already exists, i can wait for a second to
get a new nJulian + Seconds() .
(all that in theory). I will try that right now.
Best regards
Yannis
elcapitan48[at]yahoo.com
Ray Marron wrote:
> Internally, Clipper dates are Julian date integers:
>
> nJulian := dDate - ctod("")
>
> Back to date:
>
> dDate := ctod("") + nJulian
>
> As far as this double, like Dave said, what's your base date?
>
> In Delphi, TDateTime is a double where 1899-12-30 is day 0 (the fractional
> part is the time). To convert to a Delphi equivalent integer, you would do:
>
> nDelphiDate := (dDate - StoD('18991230')) - ctod("")
>
> As far as making it a true "double", it depends on what Clipper
> implementation you're using and what you're trying to pass it to.
>
| |
| Dave Pearson 2004-12-01, 8:55 pm |
| * Ray Marron <me@privacy.net>:
> "Dave Pearson" <davep.news@davep.org> wrote in message
> news:slrncqrrbd.nkd.davep.news@hagbard.davep.org...
>
> [SNIP]
>
> Must be xHarbour - those function names are too long to be considered
> different in CA-Clipper!
Hence me mentioning that it was with xHarbour. I do so like being able to
use sensible identifier names. ;)
> One of these days I've got to get around to trying xHarbour. Maybe when
> I'm done with all those books I've been meaning to read... :)
My Windows environment is pretty much DOS-software free these days (I still
keep a copy of DBU kicking around, that's about it) but it's always nice to
have something Clipper-ish installed for some Clipper hacking. If you can
use CA-Clipper you can use xHarbour.
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Ross McKenzie 2004-12-01, 8:55 pm |
| On Wed, 01 Dec 2004 23:13:44 +0200, Yannis <Trentis@trentis.gr> wrote:
>Thank you guys for the hint !
>I can use nJulian + Seconds() to get a unique number (every second),
>to use it as part of customer code in a database.
>To be sure, i can perform a s just before saving a new customers
>record, and if by any chance already exists, i can wait for a second to
>get a new nJulian + Seconds() .
>(all that in theory). I will try that right now.
>
>Best regards
>Yannis
>elcapitan48[at]yahoo.com
>
Yannis,
Phil Barnett wrote a collection of Julian date/time functions some
years ago. They are in a zip file named, surprisingly, JULIAN.ZIP on
his Oasis website. Could save you some time.
Regards,
Ross McKenzie
ValuSoft
Melbourne Australia
valusoft AT optushome DOT com DOT au
When there's a will, I want to be in it
| |
| Yannis 2004-12-01, 8:55 pm |
| Thank you Ross, i will download it :-)
Best regards
Yannis
elcapitan48[at]yahoo.com
Ross McKenzie wrote:
> Yannis,
>
> Phil Barnett wrote a collection of Julian date/time functions some
> years ago. They are in a zip file named, surprisingly, JULIAN.ZIP on
> his Oasis website. Could save you some time.
>
> Regards,
>
> Ross McKenzie
> ValuSoft
> Melbourne Australia
>
> valusoft AT optushome DOT com DOT au
>
> When there's a will, I want to be in it
| |
| Przemyslaw Czerpak 2004-12-01, 8:55 pm |
| On Wed, 01 Dec 2004 23:13:44 +0200,
Yannis <Trentis@trentis.gr> wrote:
> Thank you guys for the hint !
> I can use nJulian + Seconds() to get a unique number (every second),
> to use it as part of customer code in a database.
> To be sure, i can perform a s just before saving a new customers
> record, and if by any chance already exists, i can wait for a second to
> get a new nJulian + Seconds() .
> (all that in theory). I will try that right now.
nJulian + Seconds()
does not create unique keys.
You will have to make sth like: ( nJulian * 86400 ) + seconds()
and if you always use current time then I'll suggest to not start
the day counting at Cesar's day but chose some closer date, f.e.
01/01/2001 so the maximum value of generated keys will be much smaller.
function genTimeKey()
local nS, nD, nT
nS := seconds()
nD := date() - stod("20010101")
/* To avoid race condition at midnight in the above two lines */
nT := seconds()
if nT < nS
nS := nT
nD := date() - stod("20010101")
endif
return nD * 86400 + nS
best regards,
Przemek
| |
| Yannis 2004-12-02, 8:55 am |
| Przemyslaw , thank you !
I will use your suggestion. It is much better than what i tried since
now :-)
Best regards
Yannis
Przemyslaw Czerpak wrote:
>
> nJulian + Seconds()
> does not create unique keys.
> You will have to make sth like: ( nJulian * 86400 ) + seconds()
> and if you always use current time then I'll suggest to not start
> the day counting at Cesar's day but chose some closer date, f.e.
> 01/01/2001 so the maximum value of generated keys will be much smaller.
>
>
> function genTimeKey()
> local nS, nD, nT
>
> nS := seconds()
> nD := date() - stod("20010101")
>
> /* To avoid race condition at midnight in the above two lines */
> nT := seconds()
> if nT < nS
> nS := nT
> nD := date() - stod("20010101")
> endif
>
> return nD * 86400 + nS
>
> best regards,
> Przemek
| |
| Dave Pearson 2004-12-03, 8:55 pm |
| * Ray Marron <me@privacy.net>:
> In Delphi, TDateTime is a double where 1899-12-30 is day 0 (the fractional
> part is the time). To convert to a Delphi equivalent integer, you would
> do:
>
> nDelphiDate := (dDate - StoD('18991230')) - ctod("")
Funny you should mention that, I found myself going the other way (Delphi to
Clipper) the other day while hacking around with some xHarbour code:
,----
| Function DelphiDateTimeToDate( nDateTime As Numeric )
| Return( stod( "18991230" ) + int( nDateTime ) )
|
| Function DelphiDateTimeToTime( nDateTime As Numeric )
| Local cTime As String := ""
| Local nSeconds As Numeric
|
| // Work out the number of seconds.
| nSeconds := int( ( 24 * 60 * 60 ) * ( nDateTime - int( nDateTime ) ) )
|
| // Get the hours.
| cTime += padl( int( nSeconds / ( 60 * 60 ) ), 2, "0" ) + ":"
| nSeconds -= int( nSeconds / ( 60 * 60 ) ) * ( 60 * 60 )
|
| // Get minutes.
| cTime += padl( int( nSeconds / 60 ), 2, "0" ) + ":"
| nSeconds -= int( nSeconds / 60 ) * 60
|
| Return( cTime + padl( nSeconds, 2, "0" ) )
`----
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Dave Pearson 2004-12-04, 3:55 am |
| * Yannis <trentis@kanena.net>:
> Anyone knows how to conver the current date and time to a double number?
> or at least to a number ?
What do you want the number to represent? A number of days from a set date
in the past? What date?
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Yannis 2004-12-04, 8:55 am |
| Przemyslaw , thank you !
I will use your suggestion. It is much better than what i tried since
now :-)
Best regards
Yannis
Przemyslaw Czerpak wrote:
>
> nJulian + Seconds()
> does not create unique keys.
> You will have to make sth like: ( nJulian * 86400 ) + seconds()
> and if you always use current time then I'll suggest to not start
> the day counting at Cesar's day but chose some closer date, f.e.
> 01/01/2001 so the maximum value of generated keys will be much smaller.
>
>
> function genTimeKey()
> local nS, nD, nT
>
> nS := seconds()
> nD := date() - stod("20010101")
>
> /* To avoid race condition at midnight in the above two lines */
> nT := seconds()
> if nT < nS
> nS := nT
> nD := date() - stod("20010101")
> endif
>
> return nD * 86400 + nS
>
> best regards,
> Przemek
| |
| Ray Marron 2004-12-07, 3:55 am |
| "Dave Pearson" <davep.news@davep.org> wrote in message
news:slrncqrrbd.nkd.davep.news@hagbard.davep.org...
[...]
> Funny you should mention that, I found myself going the other way (Delphi
to
> Clipper) the other day while hacking around with some xHarbour code:
>
> ,----
> | Function DelphiDateTimeToDate( nDateTime As Numeric )
> | Return( stod( "18991230" ) + int( nDateTime ) )
> |
> | Function DelphiDateTimeToTime( nDateTime As Numeric )
> | Local cTime As String := ""
> | Local nSeconds As Numeric
[SNIP]
Must be xHarbour - those function names are too long to be considered
different in CA-Clipper!
One of these days I've got to get around to trying xHarbour. Maybe when I'm
done with all those books I've been meaning to read... :)
--
Ray Marron
| |
| Yannis 2004-12-07, 3:55 am |
| Thank you guys for the hint !
I can use nJulian + Seconds() to get a unique number (every second),
to use it as part of customer code in a database.
To be sure, i can perform a s just before saving a new customers
record, and if by any chance already exists, i can wait for a second to
get a new nJulian + Seconds() .
(all that in theory). I will try that right now.
Best regards
Yannis
elcapitan48[at]yahoo.com
Ray Marron wrote:
> Internally, Clipper dates are Julian date integers:
>
> nJulian := dDate - ctod("")
>
> Back to date:
>
> dDate := ctod("") + nJulian
>
> As far as this double, like Dave said, what's your base date?
>
> In Delphi, TDateTime is a double where 1899-12-30 is day 0 (the fractional
> part is the time). To convert to a Delphi equivalent integer, you would do:
>
> nDelphiDate := (dDate - StoD('18991230')) - ctod("")
>
> As far as making it a true "double", it depends on what Clipper
> implementation you're using and what you're trying to pass it to.
>
| |
| Yannis 2004-12-07, 3:55 am |
| Thank you Ross, i will download it :-)
Best regards
Yannis
elcapitan48[at]yahoo.com
Ross McKenzie wrote:
> Yannis,
>
> Phil Barnett wrote a collection of Julian date/time functions some
> years ago. They are in a zip file named, surprisingly, JULIAN.ZIP on
> his Oasis website. Could save you some time.
>
> Regards,
>
> Ross McKenzie
> ValuSoft
> Melbourne Australia
>
> valusoft AT optushome DOT com DOT au
>
> When there's a will, I want to be in it
| |
| Dave Pearson 2004-12-07, 3:55 am |
| * Ray Marron <me@privacy.net>:
> "Dave Pearson" <davep.news@davep.org> wrote in message
> news:slrncqrrbd.nkd.davep.news@hagbard.davep.org...
>
> [SNIP]
>
> Must be xHarbour - those function names are too long to be considered
> different in CA-Clipper!
Hence me mentioning that it was with xHarbour. I do so like being able to
use sensible identifier names. ;)
> One of these days I've got to get around to trying xHarbour. Maybe when
> I'm done with all those books I've been meaning to read... :)
My Windows environment is pretty much DOS-software free these days (I still
keep a copy of DBU kicking around, that's about it) but it's always nice to
have something Clipper-ish installed for some Clipper hacking. If you can
use CA-Clipper you can use xHarbour.
--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
| |
| Przemyslaw Czerpak 2004-12-07, 3:55 am |
| On Wed, 01 Dec 2004 23:13:44 +0200,
Yannis <Trentis@trentis.gr> wrote:
> Thank you guys for the hint !
> I can use nJulian + Seconds() to get a unique number (every second),
> to use it as part of customer code in a database.
> To be sure, i can perform a s just before saving a new customers
> record, and if by any chance already exists, i can wait for a second to
> get a new nJulian + Seconds() .
> (all that in theory). I will try that right now.
nJulian + Seconds()
does not create unique keys.
You will have to make sth like: ( nJulian * 86400 ) + seconds()
and if you always use current time then I'll suggest to not start
the day counting at Cesar's day but chose some closer date, f.e.
01/01/2001 so the maximum value of generated keys will be much smaller.
function genTimeKey()
local nS, nD, nT
nS := seconds()
nD := date() - stod("20010101")
/* To avoid race condition at midnight in the above two lines */
nT := seconds()
if nT < nS
nS := nT
nD := date() - stod("20010101")
endif
return nD * 86400 + nS
best regards,
Przemek
|
|
|
|
|