FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DateTime calculation
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
DateTime calculation
Posted: Thu Jan 25, 2024 11:40 PM

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
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: DateTime calculation
Posted: Fri Jan 26, 2024 01:57 AM

I figured it out.

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DateTime calculation
Posted: Fri Jan 26, 2024 09:49 PM
Code (fw): Select all Collapse
DateTime() - ( 10 / ( 24 * 60 ) )
Regards



G. N. Rao.

Hyderabad, India
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: DateTime calculation
Posted: Fri Jan 26, 2024 09:57 PM

Hi Rao, thank you. I had found it in xHarbour documentation

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 179
Joined: Fri Dec 07, 2007 01:26 PM
Re: DateTime calculation
Posted: Sat Jan 27, 2024 07:51 AM
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:

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



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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: DateTime calculation
Posted: Sat Jan 27, 2024 07:57 AM
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 (fw): Select all Collapse
// 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
Posts: 179
Joined: Fri Dec 07, 2007 01:26 PM
Re: DateTime calculation
Posted: Sat Jan 27, 2024 09:16 AM
Dear Antonio,

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

have a nice weekend and kind regards
ruth

Continue the discussion