DateTime calculation

DateTime calculation

Postby cdmmaui » 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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: DateTime calculation

Postby cdmmaui » Fri Jan 26, 2024 1:57 am

I figured it out.
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: DateTime calculation

Postby nageswaragunupudi » Fri Jan 26, 2024 9:49 pm

Code: Select all  Expand view
DateTime() - ( 10 / ( 24 * 60 ) )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: DateTime calculation

Postby cdmmaui » Fri Jan 26, 2024 9:57 pm

Hi Rao, thank you. I had found it in xHarbour documentation
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: DateTime calculation

Postby Ruth » Sat Jan 27, 2024 7: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:
[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
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm

Re: DateTime calculation

Postby Antonio Linares » Sat Jan 27, 2024 7: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: Select all  Expand view
// 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
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DateTime calculation

Postby Ruth » Sat Jan 27, 2024 9:16 am

Dear Antonio,

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

have a nice weekend and kind regards
ruth
User avatar
Ruth
 
Posts: 169
Joined: Fri Dec 07, 2007 1:26 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests