Author Topic: Function Timestamp  (Read 14430 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Function Timestamp
« Reply #45 on: October 03, 2021, 11:06:43 am »
@zaadstra

Can yours be used to calculate the difference between 2 dates and times?

Is there a limit to earliest date & time (like start of Gregorian calendar, assuming Gregorian calculations) and future dates like something in year 2050?

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: Function Timestamp
« Reply #46 on: October 03, 2021, 11:36:24 am »
@zaadstra

Can yours be used to calculate the difference between 2 dates and times?

Is there a limit to earliest date & time (like start of Gregorian calendar, assuming Gregorian calculations) and future dates like something in year 2050?

I think yes,  that's what I intend to use it for.  Although my date/times will be in this age, I have tested working on dates from the year 488 to 2521 and the results checked out with the website.

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: Function Timestamp
« Reply #47 on: October 03, 2021, 11:53:27 am »
You may remove the loop and setup the tm$ yourself to verify values.  It gets coverted to UNIX time, and then the outcome is converted back.

Gregorian calendar was introduced in the year 1582, and Julian calendar was introduced by Julius Caesar in 46 BC.  Julian date 0 is in the year -4712.... There has been a lot of hassling with the calendars during the ages.  This Julian calculation with a Gregorian sauce on top calculates the current leap years (UNIX to timestamp routine).  You might discuss if that is accurate befoure introducing it before 1582, I did not research that.
Wikipedia and other sites have a lot of information.

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: Function Timestamp
« Reply #48 on: October 03, 2021, 05:25:29 pm »
I wanted to display difference between epoch times in the Exif program, and since you asked for it @bplus, here it goes:

Code: QB64: [Select]
  1. FUNCTION TimeStampDiff$ (tm_epoch&&)
  2.    ' call with argument: UNIX epoch time difference - a number of seconds - best called with ABS(val1_epoch&& - val2_epoch&&)
  3.    year&& = tm_epoch&& \ 31536000: tm_epoch&& = tm_epoch&& - year&&
  4.    month&& = tm_epoch&& \ 2678400: tm_epoch&& = tm_epoch&& - month&&
  5.    day&& = tm_epoch&& \ 86400: tod = tm_epoch&& - day&& * 86400
  6.    hh = tod \ 3600
  7.    mm = (tod - hh * 3600) \ 60
  8.    ss = tod MOD 60
  9.    TimeStampDiff$ = RIGHT$(STR$(10000 + year&&), 4) + ":" + RIGHT$(STR$(100 + month&&), 2) + ":" + RIGHT$(STR$(100 + day&&), 2) + " " + RIGHT$(STR$(100 + hh), 2) + ":" + RIGHT$(STR$(100 + mm), 2) + ":" + RIGHT$(STR$(100 + ss), 2)

This looks like 0000:00:00 00:12:18 for an epoch diff of 738. 
« Last Edit: October 06, 2021, 03:29:41 pm by zaadstra »