Date and Time range
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: Date and Time range

  1. #1
    Join Date
    Jul 2006
    Posts
    203

    Date and Time range

    When we get date, we receive a WORD value which contains date with year. So Date is stored in 2 bytes. What is range for these 2 bytes? What could be the minimum value and what is maximum value. Is 0x0058 a valid value for date?

    Time is also stored in 2 bytes.What is the range for time

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Date and Time range

    What "date" and "time" functions do you mean?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,281

    Re: Date and Time range

    Depends what you are talking about, but if it is the time_t returned by function time(), then this is what cplusplus.com has to say about it:

    Type capable of representing times and support arithmetical operations.

    This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.

    It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.
    If you make the assumption that time_t is an integral type (just like size_t), then yes, it is OK.

    If you are talking about the tm struct, then it is not OK, as each member should be assigned one by one.

    Finally, if you are manipulating any other time type, well I don't have enough details to help.
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Date and Time range

    Seeing that he's using the terminology WORD, I would assume this is some Windows timing structure :P

    Usually date and time is stored at a 32 or 64 bit unsigned integer using a UNIX timestamp. On Windows, I have no idea, probably DOS time or VISI time, but if you use the built in C functions, you are guaranteed to get UNIX... *I think*

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,281

    Re: Date and Time range

    Quote Originally Posted by ninja9578 View Post
    Seeing that he's using the terminology WORD, I would assume this is some Windows timing structure :P

    Usually date and time is stored at a 32 or 64 bit unsigned integer using a UNIX timestamp. On Windows, I have no idea, probably DOS time or VISI time, but if you use the built in C functions, you are guaranteed to get UNIX... *I think*
    "guaranteed" is so ambiguous... I think every implementation I know of does it, but the standard does no mandate it...

    I hate those cases.
    Last edited by monarch_dodra; June 1st, 2010 at 08:26 AM.
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Date and Time range

    No, but the terminology "time_t" comes from UNIX.

  7. #7
    Join Date
    Jul 2006
    Posts
    203

    Re: Date and Time range

    Lets consider Windows OS only
    FAT file system keeps create date, create time etc for any file in 2 bytes (WORD)
    i am talking about the range of these 2 bytes

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Date and Time range

    From MSDN (File Times):
    on Windows NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Furthermore, FAT records times on disk in local time, while NTFS records times on disk in UTC, so it is not affected by changes in time zone or daylight saving time.
    See also http://support.microsoft.com/kb/127830
    Victor Nijegorodov

  9. #9
    Join Date
    Jul 2006
    Posts
    203

    Re: Date and Time range

    the best way for me to check the range for any time or date is to use the function
    which function returns time in 2 bytes. also which function returns date in 2 bytes

  10. #10
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Date and Time range

    It would be better if you had explained what (and what for?) you are trying to achieve with such a function as well as with 2-bytes date and 2-bytes time values.
    Victor Nijegorodov

  11. #11
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Date and Time range

    How many people still use FAT though? The only reason to use FAT is if you dual boot with OSX, as it can't write to NTSF.

  12. #12
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Date and Time range

    Quote Originally Posted by MFCQuery View Post
    Lets consider Windows OS only
    FAT file system keeps create date, create time etc for any file in 2 bytes (WORD)
    i am talking about the range of these 2 bytes
    See the FAT description in Wiki
    Victor Nijegorodov

  13. #13
    Join Date
    Jul 2006
    Posts
    203

    Re: Date and Time range

    thanks for giving the wiki page link
    i wanted to know about what these 2 bytes contain
    wiki page answered this

  14. #14
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Date and Time range

    Quote Originally Posted by MFCQuery View Post
    thanks for giving the wiki page link
    i wanted to know about what these 2 bytes contain
    wiki page answered this
    If you had asked something like "What is the date/time structure of the file in FAT?" or "How is file date/time saved in FAT system?" you would get an answer yesterday!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center