# Urgent: Time and Date calculations.

Hi,

Since I am creating (atleast trying) a trail version of my software, I am concerned about the time and date parameters.
The user can simply turn his bios or windows clock back and still use the software if using time() or any other functions which are provided by Borland.

To avoid this I decided to get the current time from the time servers.
My current result is the current time (year,month,day,hour,minute,second) stored in different integers.

The main problem of mine is the calculation if the year has changed. For example if the program was started using at 21 of December, 2008 and the current date is 2 January 2009 and the trail period is 30 days the program should still stay active. Also there is alot of problems with february which has a different day count every 4 years and so on. Also every second month has different ammount of days in  it,also daylight saving and other factors.

Well the daylight saving is the last thing to worry about. I'll give away that one free hour :).

I could use time(0) difftime() functions to calculate the correct difference (I hope that they will be correct), but first I have to understand how to convert the current date and the trail start date to the format which uses 1970 01 01 00:00 as the start of calculation. Then understand how to turn the difference of time since that date to seconds. Calculating it would also be a problem because of the February.

Since the program will only be a three day trail the miscalulations of february could turn up a disaster which could end up a 20 or more day trail instead of 3.

Also readed about the Julian Time format, but I'm not sure if it suits my needs.

I saw an object called DateTime in .NET which would solve all my problems. Maby there is something similar in C++/Borland C++?
Editors IDEsMath / ScienceProgramming Theory

Last Comment
Jammer1224

8/22/2022 - Mon
ozo

#include <time.h>

double
difftime(time_t time1, time_t time0);

char *
asctime(const struct tm *tm);

struct tm *
localtime(const time_t *clock);

struct tm *
gmtime(const time_t *clock);

time_t
mktime(struct tm *tm);

time_t
timegm(struct tm *tm);

size_t
strftime(char * restrict buf, size_t maxsize,
const char * restrict format, const struct tm * restrict timeptr);

Jammer1224

I guess you didn't read the whole post.
all functions require a parameter of time_t.
and time_t = time since 1970 01 01 00:00 in seconds.
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Jammer1224