#1
  1. No Profile Picture
    I am here to share knowledge
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    India
    Posts
    83
    Rep Power
    12

    How to compare time


    This is my the part of the code in asp in which i want that if record is getting submitted between morning 6 am to night 12 pm
    the value of sdate should be current date or if the time is between night 12 to morning 6 the value of sdate should be the previous date but this comparison is not working please help me.

    if (time()>"06:00:00 AM") and (time()<"07:00:00 AM") then
    sdate = Year(Date()) & "-" & Month(Date()) & "-" & Day(Date())
    Response.Write(sdate)
    End IF

    I am using MySQL as my backend

    Thanx in advance Rahul
    Rahul

    Small things lead to perfection and perfection is not a small thing.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Canada, Quebec, Montreal
    Posts
    410
    Rep Power
    12

    You might


    want to have a look into the DateDiff() function and yes you can compare time, there is no TimeDiff() function...have a look here:

    http://www.devguru.com/Technologies/.../datediff.html

    Also, you are comparing time() with a string that looks like a time value "06:00:00 AM" but in fact it is a string...

    try converting that *string* using Cdate()

    if (time()>CDate("06:00:00 AM")) and (time()<CDate("07:00:00 AM")) then
    . . .


    try that otherwise look into the DateDiff() function


    Hope this helps!
    Sincerely

    Vlince
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0
    Originally Posted by rgdubey
    This is my the part of the code in asp in which i want that if record is getting submitted between morning 6 am to night 12 pm
    the value of sdate should be current date or if the time is between night 12 to morning 6 the value of sdate should be the previous date but this comparison is not working please help me.

    if (time()>"06:00:00 AM") and (time()<"07:00:00 AM") then
    sdate = Year(Date()) & "-" & Month(Date()) & "-" & Day(Date())
    Response.Write(sdate)
    End IF

    I am using MySQL as my backend

    Thanx in advance Rahul
    Please comment
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,449
    Rep Power
    4539
    Originally Posted by destinystar
    Please comment
    This is not an acceptable question, and you have resurrected a 9 year old thread.

    This topic is closed.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo