Date storage of the system

Asked

Viewed 70 times

0

I need to capture the system date and store it in an entire variable, as I will need to compare it to a date that will be informed by the user. I found the function _strdate that stores the date on the formed DD/MM/AA in a string, however it is not so interesting in my case, because I intend that the date informed by the user is in the format DDMMAAAA. Is there any way to capture the date in this format and convert it to whole? Also, how can I make the comparison with another informed date? I will need to analyze number by number?

1 answer

1

Data is a complicated business. In my opinion you should store as a string and use the YYYYMMDD format, because then a string comparison serves to tell if one date is bigger than another. If the user types DDMMAAAA, it is not difficult to reorder the parts.

Only use integers for dates if you want to store the timestamp, for example the value returned by the time() function. It returns the number of seconds since 1/1/1970 0:00 GMT, so the "zero" moment corresponded to 12/31/1969 21:00 in Brazil. The advantage of timestamp is that it is valid all over the world (a larger timestamp suit happened after a smaller timestamp, although in a place with a different time zone).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.