Calculate Yesterday Date

M

Manny Chohan

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

Thanks

manny
 
B

Bob Barrows [MVP]

Manny said:
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
 
D

Dave Anderson

Manny said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top