Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    string (datetime) to numeric for comparision (2000/2003/...)

    Hi

    Is it possible to convert a 'date-time' string into a numeric value for comparison with another numeric value or perhaps there is a better way of comparing two date-time strings? String comparison obviously doesn't work here. For example, if I have two strings

    datetimeA = "06 March 2006 15:36:18"
    datetimeB= "01 January 2007 12:10:10"

    I would like to do something like:

    if datetimeB > datetimeA then
    datetimeB is later then datetimeA therefore do something
    else
    otherwise (datetimeA is greater than datetimeB) do something else

    Thanks

    Robie.
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: string (datetime) to numeric for comparision (2000/2003/...)


  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: string (datetime) to numeric for comparision (2000/2003/...)

    Hi Robie,

    Where datetimeA and datetimeB are bookmarked, you could use a field coded as:
    {IF{REF datetimeB @ "YYYYMMDDMMHHmmSS}>{REF datetimeA @ "YYYYMMDDMMHHmmSS} "datetimeB is later than datetimeA therefore do something" "datetimeB is NOT later than datetimeA therefore do something else"}

    In a macro you could use:
    Sub Test()
    Dim datetimeA As String
    Dim datetimeB As String
    datetimeA = "06 March 2006 15:36:18"
    datetimeB = "01 January 2007 12:10:10"
    If CDate(datetimeB) > CDate(datetimeA) Then
    MsgBox "datetimeB: " & datetimeB & " is later than datetimeA: " & datetimeA
    Else
    MsgBox "datetimeB: " & datetimeB & " is NOT later than datetimeA: " & datetimeA
    End If
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: string (datetime) to numeric for comparision (2000/2003/...)

    Hey - Thanks Hans and Macropod. Just what I needed. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    I downloaded your (Macropod) date stuff. Wow Fantastic. It will come in so handy for me. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

    Thanks very much.

    Robie
    Thanks.
    Robie

Posting Permissions

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