DateTime calculation

Post Reply
User avatar
cdmmaui
Posts: 693
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong
Contact:

DateTime calculation

Post by cdmmaui »

Hello,

Is it possible to perform a DateTime calculation to get current time minus 10 minutes? For example

cTenMinutesBefore := DateTime() - 10

Thank you!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
Posts: 693
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong
Contact:

Re: DateTime calculation

Post by cdmmaui »

I figured it out.
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: DateTime calculation

Post by nageswaragunupudi »

Code: Select all | Expand

DateTime() - ( 10 / ( 24 * 60 ) )
Regards

G. N. Rao.
Hyderabad, India
User avatar
cdmmaui
Posts: 693
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong
Contact:

Re: DateTime calculation

Post by cdmmaui »

Hi Rao, thank you. I had found it in xHarbour documentation
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
Ruth
Posts: 172
Joined: Fri Dec 07, 2007 1:26 pm
Contact:

Re: DateTime calculation

Post by Ruth »

dear all,

I would also like to kindly ask assistance with date and time handling.
specifically: is it possible to convert a harbour date variable into a "unix timestamp expressed in milliseconds" (hope this is the correct term)?

I am working on a project where I need to pass arrival and departure dates to a url.
the expected format is something like this:
[url]https://be.bookingexpert.it/book/simple/noavail?checkin=1707523200000&checkout=1708124400000&hotel=11308&guesttypes[0][37]=2&ages[0][37]=18&ages[0][37]=18&layout=782&lang=de&currency=EUR&beginsearch=1&isnewsearch=1&searchId=218d74e0-8bfd-43df-970d-e5f4c6f59ed1&nsid=fb5f36a1-7c31-40de-9c6e-8c7837b6a130&winding=1&searchId=e7cfbe49-4afc-4c0e-ae7b-69180634164f[/url]

where checkin=1707523200000 is the 10.02.2024 and
checkout=1708124400000 is the 17.02.2024

thank you very much in advance and kind regards
ruth
User avatar
Antonio Linares
Site Admin
Posts: 42256
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: DateTime calculation

Post by Antonio Linares »

Dear Ruth,

good morning

I just copied and pasted your post into chatgpt and the answer seems fine :-) (not exactly correct, but the explanation seems fine)
Yes, it looks like the timestamp you provided is in milliseconds since the Unix epoch. To convert a Harbour date variable into a Unix timestamp expressed in milliseconds, you need to follow these steps:

Get the date value from the Harbour date variable.
Convert the date value to the Unix timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).
Multiply the Unix timestamp by 1000 to convert it to milliseconds.
Here's a simple example in Harbour script:

Code: Select all | Expand

// Assuming you have a Harbour date variable named myDate
myDate := DToT(DATE(2024, 02, 10))

// Step 2: Convert to Unix timestamp (seconds)
unixTimestamp := myDate - DATE(1970, 01, 01)

// Step 3: Convert to milliseconds
unixTimestampMilliseconds := unixTimestamp * 1000

? "Unix Timestamp in milliseconds:", unixTimestampMilliseconds
 
This code assumes myDate contains the Harbour date variable you want to convert. Please replace myDate with your actual date variable. The resulting unixTimestampMilliseconds will be in the format you can use in your URL.

Make sure to adjust the code based on your actual Harbour date handling methods, as it may vary depending on the context of your project.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Ruth
Posts: 172
Joined: Fri Dec 07, 2007 1:26 pm
Contact:

Re: DateTime calculation

Post by Ruth »

Dear Antonio,

thank you very much...this is wonderful!!!
it is running now :-)

have a nice weekend and kind regards
ruth
Post Reply