asp - two dates

Results 1 to 4 of 4

Thread: asp - two dates

  1. #1
    Join Date
    Dec 1969

    Default asp - two dates

    In asp, I want to compare current date (function “Now”) and date who is stored in some variable. How I can know which date is older?<BR><BR>Of course there is way: complicated if-then-else loop which compare every segment of current date (minute(now), hour(now), Day(Date), Month(Date)) with every part of “variable date”. This way isn’t elegant but “!*#$$%”... :-) You know what I mean...<BR><BR>Can anybody explain me how I can do that?<BR><BR>Thanx

  2. #2
    LeeAnnie Guest

    Default RE: asp - two dates

    I would just use cDate()...<BR><BR>if cDate(now()) &#062; cDate(myDate) then<BR>response.write(Now() & "is greater than " & myDate)<BR>end if

  3. #3
    Join Date
    Dec 1969

    Default No need for cdate

    as already dates anduse date instead of now if not concerned about time<BR><BR>if date&#062;mydate

  4. #4
    Join Date
    Dec 1969

    Default Yes and no...

    Krank is right: If the variable or value is already of type Date, there is certainly no need to use CDate.<BR><BR>Date() and Now(), for example, are always of type Date.<BR><BR>And if you get a date from a date/time field in a DB, via:<BR>&nbsp; &nbsp; myDate = RS("someDateTimeField")<BR>it will be a Date type.<BR><BR>But if you get the date from user input or from any kind of string, then you should use CDate to both convert it to a Date variable *and* ensure that it is a valid date.<BR><BR>Don&#039;t know if something is of type Date or not???<BR><BR>Test it:<BR><BR>Response.Write TypeName( theThingYouAreNotSureAbout )<BR><BR>If that doesn&#039;t write "Date" onto the browser screen, then use CDate.<BR><BR>Want to be safe when you aren&#039;t sure? Then go ahead and use CDate. Even if the thing already was a Date value, it won&#039;t hurt.<BR><BR>

Posting Permissions

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