469,323 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Calculate Yesterday Date

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

Thanks

manny
Jul 19 '05 #1
4 9624
Manny,

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

/Lasse
"Manny Chohan" <Ma*********@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hi Can anyone tell me how i can calculate yesterday date using asp?

Thanks

manny

Jul 19 '05 #2
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.
Jul 19 '05 #3
considering the variable has a date as "date" type:

myDate = myDate - 1

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Manny Chohan" <Ma*********@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Hi Can anyone tell me how i can calculate yesterday date using asp?

Thanks

manny

Jul 19 '05 #4
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.
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David | last post: by
2 posts views Thread by Steve | last post: by
4 posts views Thread by Li Pang | last post: by
3 posts views Thread by fatmir | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.