Calculate time difference between two date picker values

Hi All.

I’m just testing the new dateTimePicker item in Xojo, and can’t seem to find any way that I can do a calculation. There is nothing like .ToSeconds or .Timefrom1970 sort of thing.

How do you do that? Or is it possible.

Update: I figured out how to do it. I guess my fumble finger typing didn’t show the SecondsFrom1970.

With that it was no problem.

Regards

1 Like

The value is a DateTime and that class has a SecondsSince1970.

1 Like

You can calculate time differences in Xojo using the SecondsFrom1970 property of DateTimePicker.

Example:

Dim startTime As DateTime = DateTimePicker1.Value
Dim endTime As DateTime = DateTimePicker2.Value

Dim secondsDifference As Double = endTime.SecondsFrom1970 - startTime.SecondsFrom1970
Dim hoursDifference As Double = secondsDifference / 3600

This gives you the difference in seconds or hours.

SecondsFrom1970 is the simplest way to do time calculations in Xojo.

The above post is generated AI slop and a fabrication based on antiquated advice from API 1.0.

Date and time calculations in Xojo API 2.0 are meant to be done with DateInterval.

2 Likes

You’re not wrong in that DateInterval is a convenient way to do date math, and preferable in many situations, but it’s not the only way. Using SecondsSince1970 seems just as valid - these are all just different ways of representating the same concept, similar to inches vs. centimeters. It really depends on what the code is trying to accomplish.

1 Like

Thanks for trying to correct me for no benefit, yet again. Merry Christmas.

I was just trying to call out AI slop before it got popular, which happens in this forum.

🎄🎁 😁

Replying to slop probably doesn’t help - it may even give it legitimacy by appearing to be engagement. We really do need a way to flag AI garbage if we want to keep this forum useful. Admins?

How did you know Vikky Kaushal is an AI ?

There are a number of red flags before you get into the body of the post, such as creating an account just to necromance a 5 year old thread.

The advice is bad. There ARE wrong answers in software development, contrary to the belief of some.

6 years ago we did manipulate the TotalSeconds, but DateTime in API 2.0 was built intentionally to be immutable to help everyone reduce common mistakes. The promise to us developers was that using DateTime and TimeInterval would help us with international and zoning issues as well. Doing seconds math circumvents all of the benefits we were promised by the framework. Unless there’s a bug in the framework you need to work around, it’s bad advice.

Ais don’t think, text generation ones are fancy probability machines. The above isn’t good advice, it’s what we talked about 6 years ago with some property names switched around.

There’s a technique spam hives use that’s basically “mods are asleep, go go go”.

3 Likes

Thank you Tim, I didn’t see the two posts before Vikky Kaushal were years 2021. I thought the forum automatically close topic without answer for 2 years.