comparing date time

Discussion in 'C++' started by Javier, Feb 21, 2005.

  1. Javier

    Javier Guest

    Hi

    I´ve a routine that will read date and times in a vector of strings ie:

    30/02/2005 19:20


    In some moment I´ll need to check if there are in vector a date like
    current date with a time >= current time and <= (current time + n minutes)

    I´m new to C++ but, nevertheless, I know how to search in a vector, but
    how could I make date time comparisons ?



    Thanks in advance

    J


    PD: I´m working with VC++ 6
     
    Javier, Feb 21, 2005
    #1
    1. Advertising

  2. Javier

    osmium Guest

    "Javier" writes:

    > I´ve a routine that will read date and times in a vector of strings ie:
    >
    > 30/02/2005 19:20


    Not to change the subject but where on this planet is such a time
    representation used and valid?
     
    osmium, Feb 21, 2005
    #2
    1. Advertising

  3. Javier

    Ron Natalie Guest

    osmium wrote:
    > "Javier" writes:
    >
    >
    >>I´ve a routine that will read date and times in a vector of strings ie:
    >>
    >>30/02/2005 19:20

    >
    >
    > Not to change the subject but where on this planet is such a time
    > representation used and valid?
    >
    >

    I've seen that ordering, but not with that punctuation in the Military
    and frequently in Europe.
     
    Ron Natalie, Feb 21, 2005
    #3
  4. osmium wrote:

    >>30/02/2005 19:20

    >
    >
    > Not to change the subject but where on this planet is such a time
    > representation used and valid?



    What exactly do you think is invalid? In Europe dates are in the form
    dd/mm/yyyy or dd/mm/yy.




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 21, 2005
    #4
  5. Ioannis Vranos wrote:

    >>> 30/02/2005 19:20

    >>
    >>
    >>
    >> Not to change the subject but where on this planet is such a time
    >> representation used and valid?

    >
    >
    >
    > What exactly do you think is invalid? In Europe dates are in the form
    > dd/mm/yyyy or dd/mm/yy.


    .... and time is used in both 12h/24h formats.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 21, 2005
    #5
  6. Javier

    osmium Guest

    "Ron Natalie" writes:

    > osmium wrote:
    >> "Javier" writes:
    >>
    >>
    >>>I´ve a routine that will read date and times in a vector of strings ie:
    >>>
    >>>30/02/2005 19:20

    >>
    >>
    >> Not to change the subject but where on this planet is such a time
    >> representation used and valid?
    >>
    >>

    > I've seen that ordering, but not with that punctuation in the Military
    > and frequently in Europe.


    It sure looks like February 30th to me.
     
    osmium, Feb 21, 2005
    #6
  7. osmium wrote:
    >
    > "Ron Natalie" writes:
    >
    > > osmium wrote:
    > >> "Javier" writes:
    > >>
    > >>
    > >>>I´ve a routine that will read date and times in a vector of strings ie:
    > >>>
    > >>>30/02/2005 19:20
    > >>
    > >>
    > >> Not to change the subject but where on this planet is such a time
    > >> representation used and valid?
    > >>
    > >>

    > > I've seen that ordering, but not with that punctuation in the Military
    > > and frequently in Europe.

    >
    > It sure looks like February 30th to me.


    C'mon. The OP was simply typing an example without thinking and made a
    mistake in the values. That doesn't change his problem.

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Feb 21, 2005
    #7
  8. Ioannis Vranos wrote:

    >> What exactly do you think is invalid? In Europe dates are in the form
    >> dd/mm/yyyy or dd/mm/yy.

    >
    >
    > ... and time is used in both 12h/24h formats.



    I just realised the OP's 30th of February...




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 21, 2005
    #8
  9. On Mon, 21 Feb 2005 09:06:35 -0500, Ron Natalie
    <> wrote:

    > osmium wrote:
    >> "Javier" writes:
    >>
    >>>I´ve a routine that will read date and times in a vector of strings ie:
    >>>
    >>>30/02/2005 19:20

    >>
    >> Not to change the subject but where on this planet is such a time
    >> representation used and valid?
    >>

    > I've seen that ordering, but not with that punctuation in the Military
    > and frequently in Europe.


    Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
    separators). Normal UK date notation is dd/mm/yyyy (continental Europe
    tends to use dd.mm.yyyy, using - as separator is also common; prior to
    2000 the year was often 2 digits instead of 4 (and sometimes still is
    that way). Only the UK and dependencies now generally use the 12-hour
    clock, a lot of European languages don't even have a concept of AM and
    PM, and most public bodies in the UK now use 24-hour (buses, trains,
    etc.).

    (Of course, none of them actually use the 30th of February in any year,
    but it was the representation which was being queried not the value...)

    Chris C
     
    Chris Croughton, Feb 21, 2005
    #9
  10. Javier

    Javier Guest

    osmium wrote:
    > "Javier" writes:
    >
    >
    >>I´ve a routine that will read date and times in a vector of strings ie:
    >>
    >>30/02/2005 19:20

    >
    >
    > Not to change the subject but where on this planet is such a time
    > representation used and valid?
    >
    >



    How much of this planet do you know ?

    In Europe and all South America, people use to represent dates in that
    way: dd/mm/yyyy. May be you need to make a trip through the 99,99% of
    the world you unknown... :)

    In this case, this data comes from a Visual Fox application and is
    stored in that way in a MSDE.

    J
     
    Javier, Feb 21, 2005
    #10
  11. Javier

    osmium Guest

    "Javier" writes:

    > osmium wrote:
    >> "Javier" writes:
    >>
    >>
    >>>I´ve a routine that will read date and times in a vector of strings ie:
    >>>
    >>>30/02/2005 19:20

    >>
    >>
    >> Not to change the subject but where on this planet is such a time
    >> representation used and valid?
    >>
    >>

    >
    >
    > How much of this planet do you know ?


    Does the word "valid" have any meaning at all to you?
     
    osmium, Feb 21, 2005
    #11
  12. On Mon, 21 Feb 2005 13:29:19 -0800, osmium
    <> wrote:

    > "Javier" writes:
    >
    >> osmium wrote:
    >>> "Javier" writes:
    >>>
    >>>>I´ve a routine that will read date and times in a vector of strings ie:
    >>>>
    >>>>30/02/2005 19:20
    >>>
    >>> Not to change the subject but where on this planet is such a time
    >>> representation used and valid?

    >>
    >> How much of this planet do you know ?

    >
    > Does the word "valid" have any meaning at all to you?


    You said "time representation", that representation is valid. The date
    itself is not valid, but that's not what you asked...

    Chris C
     
    Chris Croughton, Feb 21, 2005
    #12
  13. Javier wrote:
    >
    > Hi
    >
    > I´ve a routine that will read date and times in a vector of strings ie:
    >
    > 30/02/2005 19:20
    >
    > In some moment I´ll need to check if there are in vector a date like
    > current date with a time >= current time and <= (current time + n minutes)
    >
    > I´m new to C++ but, nevertheless, I know how to search in a vector, but
    > how could I make date time comparisons ?


    To get back to the question asked:
    In order to compare such dates, you will need to split the complete string
    into pieces and compare those pieces. This gets simple, if the format of
    the time string is constant and always the same.

    Search out for string manipulation functions, especially on how to get
    a substring from a string. The other thing that will be handy, is a function
    which converts a string representation of a number into a number.

    Once you have all those pieces (day, month, year, hour, minute) as numbers,
    comparing them should not be a problem. When you do your tests, make sure you
    also test the cases, where the time intervall crosses midnight :)

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Feb 22, 2005
    #13
  14. Javier wrote:
    >
    > Hi
    >
    > I´ve a routine that will read date and times in a vector of strings ie:
    >
    > 30/02/2005 19:20
    >
    >
    > In some moment I´ll need to check if there are in vector a date like
    > current date with a time >= current time and <= (current time + n minutes)
    >
    > I´m new to C++ but, nevertheless, I know how to search in a vector, but
    > how could I make date time comparisons ?
    >
    >
    >
    > Thanks in advance
    >
    > J
    >
    >
    > PD: I´m working with VC++ 6


    Now, I bet you didn't expect to kick off a flame war about time
    formatting with this topic did you? :D

    As to your problem:
    I think it would be a better idea to have your date/time being
    represented by some class than by plain strings, so you can compare
    using operator==. I haven't worked with it, but I suggest you have a
    look at boost::date_time
    http://www.boost.org/libs/date_time/doc/index.html

    Maybe they have what you need.

    --
    Matthias Kaeppler
     
    Matthias Kaeppler, Feb 22, 2005
    #14
  15. Chris Croughton wrote:
    > Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
    > separators). Normal UK date notation is dd/mm/yyyy (continental Europe
    > tends to use dd.mm.yyyy, using - as separator is also common; prior to
    > 2000 the year was often 2 digits instead of 4 (and sometimes still is
    > that way). Only the UK and dependencies now generally use the 12-hour
    > clock, a lot of European languages don't even have a concept of AM and
    > PM, and most public bodies in the UK now use 24-hour (buses, trains,
    > etc.).


    Another benefit of using ISO8601 time is that comparison is reduced to
    plain old string comparison. The documentation of ISO8601 time that I
    have seen uses "-" instead of ".": yyyy-mm-ddThh:mm:ss.
     
    Eric Sokolowsky, Feb 22, 2005
    #15
  16. On Tue, 22 Feb 2005 08:51:48 -0500, Eric Sokolowsky
    <> wrote:

    > Chris Croughton wrote:
    >> Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
    >> separators). Normal UK date notation is dd/mm/yyyy (continental Europe
    >> tends to use dd.mm.yyyy, using - as separator is also common; prior to
    >> 2000 the year was often 2 digits instead of 4 (and sometimes still is
    >> that way). Only the UK and dependencies now generally use the 12-hour
    >> clock, a lot of European languages don't even have a concept of AM and
    >> PM, and most public bodies in the UK now use 24-hour (buses, trains,
    >> etc.).

    >
    > Another benefit of using ISO8601 time is that comparison is reduced to
    > plain old string comparison. The documentation of ISO8601 time that I
    > have seen uses "-" instead of ".": yyyy-mm-ddThh:mm:ss.


    You're right, I was thinking of the continental version when I typed
    that bit (actually, I typed it without separators and then added them,
    and added the wrong ones). Having it comparable with a string
    comparison makes things very easy.

    Chris C
     
    Chris Croughton, Feb 22, 2005
    #16
  17. Chris Croughton wrote:

    > You're right, I was thinking of the continental version when I typed
    > that bit (actually, I typed it without separators and then added them,
    > and added the wrong ones). Having it comparable with a string
    > comparison makes things very easy.



    My first thought is that the default std::string comparison operators
    will do the job (lexicographical comparison), so if we have


    string("27/02/2005 19:20") < string("28/02/2005 19:20")


    will always be true as also


    string("27/02/2005 19:19") < string("27/02/2005 19:20").


    So the only thing needed, is the input to be checked whether it is in
    the correct string format for the program (here "dd/mm/yyyy' 'hh:mm").




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 22, 2005
    #17
  18. Javier

    Aslan Kral Guest

    "Ioannis Vranos" <>, haber iletisinde sunlari
    yazdi:1109086397.376682@athnrd02...
    > string("27/02/2005 19:20") < string("28/02/2005 19:20")
    >
    >
    > will always be true as also
    >
    >
    > string("27/02/2005 19:19") < string("27/02/2005 19:20").
    >

    Not always.
    string("31/12/2004 23:59") > string("01/01/2005 00:00") (lexicographically)

    If the year is the same in both, what you say is true.
     
    Aslan Kral, Feb 22, 2005
    #18
  19. Aslan Kral wrote:

    > Not always.
    > string("31/12/2004 23:59") > string("01/01/2005 00:00") (lexicographically)
    >
    > If the year is the same in both, what you say is true.



    string("2004/31/12 23:59") < string("2005/01/01 00:00")


    makes the implementation simpler then. :)




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 22, 2005
    #19
  20. Ioannis Vranos wrote:

    > string("2004/31/12 23:59") < string("2005/01/01 00:00")
    >
    >
    > makes the implementation simpler then. :)



    I meant yyyy/mm/dd hh:mm :

    string("2004/12/31 23:59") < string("2005/01/01 00:00")




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Feb 22, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. .Net Sports
    Replies:
    1
    Views:
    2,674
    intrader
    Jun 25, 2005
  2. Chris Berg
    Replies:
    0
    Views:
    844
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,361
    Michael Borgwardt
    May 30, 2004
  4. Les Juby
    Replies:
    3
    Views:
    222
    Bob Barrows [MVP]
    Apr 24, 2005
  5. anagai

    Comparing input date and system date

    anagai, Oct 19, 2007, in forum: Javascript
    Replies:
    5
    Views:
    156
    Thomas 'PointedEars' Lahn
    Oct 22, 2007
Loading...

Share This Page