SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Manipulation

    Ok, question time.

    I have a date being stuck into a JS function from ASP

    the resultant code is:

    Code:
    recordDate = '10/18/2002'
    I then need to subtract a day from recordDate if the curent hour is less then 3 (using military time, so 3AM).

    So I have:

    Code:
    if hour less then 3
    {
      recordDate = recordDate - 1;
    }
    this gives an error.

    I know I can do this because I am fairly sure I have done this before. However, I simply cannot find code to do it. I have searched here to no avail.

    Thanks for the help,
    Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I am now using this code

    Code:
    d = new Date('<%=date()%>');
    d2 = new Date();
    d2 = d;
    d2.setDate(d2.getDate()-1); //not subtracting correctly
    alert(d + ' - ' + d2);
    the dates work, but when I do this it subtracts 1 from both dates. With the second alert showing 10/17/02 for both date variables.

    Thanks,
    Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New update
    Code:
    d = new Date('10/18/2002');
    d = new Date(d.getFullYear(),d.getMonth(),d.getDate()-1);
    I am now using the above code, however there has to be an easier way to do this... there just has to!

    I realy would love to use:
    d = d - 1;

    That would be nice,
    -Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is also working
    Code:
    d.setDate(d.getDate()-1);
    Hope someone sees this at some point and it helps them...
    -Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.


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
  •