Page 1 of 1
DateTime calculation
Posted: Thu Jan 25, 2024 11:40 pm
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!
Re: DateTime calculation
Posted: Fri Jan 26, 2024 1:57 am
by cdmmaui
I figured it out.
Re: DateTime calculation
Posted: Fri Jan 26, 2024 9:49 pm
by nageswaragunupudi
Re: DateTime calculation
Posted: Fri Jan 26, 2024 9:57 pm
by cdmmaui
Hi Rao, thank you. I had found it in xHarbour documentation
Re: DateTime calculation
Posted: Sat Jan 27, 2024 7:51 am
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¤cy=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
Re: DateTime calculation
Posted: Sat Jan 27, 2024 7:57 am
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.
Re: DateTime calculation
Posted: Sat Jan 27, 2024 9:16 am
by Ruth
Dear Antonio,
thank you very much...this is wonderful!!!
it is running now
have a nice weekend and kind regards
ruth