System date storage

0

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

    
asked by anonymous 08.10.2015 / 02:37

1 answer

1

Date is a tricky business. In my opinion you should store as a string and use the format YYYYMMDD, because there a string comparison is used to tell if one date is greater than another. If the user types DDMMAAAA, it is not difficult to reorder the parts.

I only advise using integer for dates if you want to store the timestamp, such as the value returned by the time () function. It returns the number of seconds since 1/1/1970 0:00 GMT, so the "zero" time was 12/31/1969 9:00 PM in Brazil. The advantage of timestamp is that it is worth all over the world (a fact with a bigger timestamp happened after another with a smaller timestamp, although in a place with a different time zone).

    
08.10.2015 / 06:03