SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Time condition

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Time condition

    Hi Guys

    Can someone tell me why this does not work:

    ---------------------
    <%if FormatDateTime(Time) > "21:00:00" and FormatDateTime(Time) < "06:00:00" then%>
    Show image
    <%else%>
    Don't show image
    <%end if%>
    ---------------------

    My page should display "Show image" between the hours of 9pm and 6am but it doesn't.

    What am I doing wrong and how do I correct it? Any help would be fully appreciated.

    I look forward to hearing from you

    Best regards

    Rod from the UK

  2. #2
    SitePoint Addict WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    253
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    http://www.powerasp.net/content/new/...e-and-time.asp

    Try using a combination of DATE and TIME, together. Without the second argument (according to the link), all you're formatting is the date without the time. (2014-05-07 is neither greater than nor less than 2014-05-07)

    HTH,

    ^_^

    UPDATE: Och.. just read your post a little closer. You can do it without the date, but be sure to format it specifically for TIME.

  3. #3
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FormatDateTime doesn't work because it requires an additional parameter. Otherwise it defaults to parameter 0, (see definitions from link below), and won't properly compare to your inputs.

    http://www.w3schools.com/vbscript/fu...atdatetime.asp

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course!

    Thank you so much Webber132456 !

    Best regards

    Rod from the UK


Bookmarks

Posting Permissions

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