ASP & Time Comparisons

They have: 330 posts

Joined: Apr 2000

I am trying to compare 2 dates and times. A lot like you would in a bulletin board like this to see if there are new posts. I know there is a way to do it but I can't get it to work.

I know with dates I can use an if statement and say "If date1 < date2 then..." but with times that doesn't seem to work. Here's what I have.

<?php
   
If CDate(MyArray(4,x)) > CDate(Request.Cookies(\"ODBStatic\")(\"LastVisitDate\")) Then
        varImage = \"Highlighted\"
    ElseIf CDate(MyArray(4,x)) = CDate(Request.Cookies(\"ODBStatic\")(\"LastVisitDate\")) Then
        If FormatDateTIME(MyArray(5,x),3) > FormatDateTIME(Request.Cookies(\"ODBStatic\")(\"LastVisitTime\"),3) Then
            varImage = \"Highlighted\"
        Else
            varImage = \"NotHighlighted\"
        End If
    Else
        varImage = \"NotHighlighted\"
    End If
?>

This seems to use the highlighted image correctly based on the date but if the date's the same I can't figure out how it decides what to do. Sometimes it's highlighted, sometimes it's not.

Thanks for any help.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

You should be able to use dates/times in comparisons no problem. Just verify that they are consistently saved in the same format. Almost all date/time problems stem from format consistency.

PJ | Are we there yet?
pjboettcher.com

They have: 330 posts

Joined: Apr 2000

In this situation I am forcing the format which should allow them to be compared right? It doesn't work for some reason.

It wouldn't matter how their saved in the database would it?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

I'm curious, why are you splitting date and time into two separate cookie values/variables? Wouldn't it be easier to just save one cookie with the last visit date and time? Then just do a comparison on that variable. If you just want to use the date or time, just extract it from the one variable.

It shouldn't matter how the date/time is saved in the database as long as it is consistent.

PJ | Are we there yet?
pjboettcher.com

They have: 330 posts

Joined: Apr 2000

Through habit I am used to saving any values seperately for reporting purposes but I see no reason to seperate the values here. I'm sure that will be the fix, thank you.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.