Calculate Yesterday Date

Discussion in 'ASP General' started by Manny Chohan, Oct 4, 2004.

  1. Manny Chohan

    Manny Chohan Guest

    Hi Can anyone tell me how i can calculate yesterday date using asp?

    Thanks

    manny
     
    Manny Chohan, Oct 4, 2004
    #1
    1. Advertising

  2. Manny Chohan

    Lasse Edsvik Guest

    Manny,

    yesterday=dateadd("d",-1,date)

    /Lasse


    "Manny Chohan" <> wrote in message
    news:...
    > Hi Can anyone tell me how i can calculate yesterday date using asp?
    >
    > Thanks
    >
    > manny
     
    Lasse Edsvik, Oct 4, 2004
    #2
    1. Advertising

  3. Manny Chohan wrote:
    > Hi Can anyone tell me how i can calculate yesterday date using asp?
    >
    > Thanks
    >
    > manny


    Depends on which scripting language you wish to use. VBScript is the
    default, so here is a vbscript solution:

    dYesterday = DateAdd("d",-1,Date())

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 4, 2004
    #3
  4. considering the variable has a date as "date" type:

    myDate = myDate - 1

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Manny Chohan" <> wrote in message
    news:...
    > Hi Can anyone tell me how i can calculate yesterday date using asp?
    >
    > Thanks
    >
    > manny
     
    Manohar Kamath, Oct 4, 2004
    #4
  5. Manny Chohan wrote:
    > Hi Can anyone tell me how i can calculate yesterday date using asp?


    You've seen the VBScript solutions. Here's a JScript one:

    var Now = new Date(),
    Yesterday = new Date(
    Now.getFullYear(),Now.getMonth(),Now.getDate()-1
    )


    The problem with your question is that neither VBScript nor JScript dates
    are free of the time of day. Consider one alternative to the above:

    var Yesterday = new Date(new Date().valueOf()-86400000)


    The difference? The first example sets the time to 12:00:00 (midnight) --
    the start of the day. The second dials the time back 24 hours, which means
    it equals the first only once every 86,400,000 milliseconds.

    And there is no difference when using VBScript. You cannot uncouple a date
    from its time when using the native date object. This is especially
    important when comparing dates.

    Before deciding on any calculation of "yesterday", therefore, your usage
    should drive your choice of calculation methods.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Oct 4, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -vr_stupids

    get "yesterday's" date in iso format

    -vr_stupids, Jan 23, 2004, in forum: Python
    Replies:
    4
    Views:
    4,213
    -vr_stupids
    Jan 24, 2004
  2. Thierry Lam

    Finding yesterday's date with datetime

    Thierry Lam, May 15, 2006, in forum: Python
    Replies:
    2
    Views:
    523
  3. Hussein B
    Replies:
    1
    Views:
    280
    Simon Brunning
    Jan 20, 2009
  4. Tim Golden
    Replies:
    0
    Views:
    567
    Tim Golden
    Oct 22, 2009
  5. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    448
    D'Arcy J.M. Cain
    Oct 22, 2009
Loading...

Share This Page