vbscript >> get date - 1 day

by Hassan » Thu, 20 Dec 2007 06:10:57 GMT

How can i get the value of the date i.e. one day minus todays date

I tried echo %date-1%

and even echo %date% -1

vbscript >> get date - 1 day

by Pegasus (MVP) » Thu, 20 Dec 2007 06:50:25 GMT

Doing date arithmetic in a batch file is cumbersome
because you have to write your own routines to
calculate the number of days since an artifical start
date, e.g. 1 January 1970. Use VB Scripting -
it has a full set of functions designed specifically
for this purpose.

vbscript >> get date - 1 day

by Richard Mueller [MVP] » Thu, 20 Dec 2007 09:36:03 GMT

In VBScript:

Wscript.Echo "Today is " & Date()
' Use DateDiff function.
Wscript.Echo "Yesterday was: " & DateAdd("d", -1, Date())
' Use the fact that dates are days since a zero date.
Wscript.Echo "Yesterday was: " & Date() - 1

Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

vbscript >> get date - 1 day

by Hassan » Thu, 20 Dec 2007 12:34:49 GMT

How to debug VB scripts ?

I cannot do it in command prompt right . So i save all that to a file called
test.vbs and then how do i run it ?

Is it "cscript test.vbs" ?

I tried to run the following from command line and it did not work

"Wscript Wscript.Echo "Yesterday was: " & Date() - 1"

"Richard Mueller [MVP]" < XXXX@XXXXX.COM > wrote in

vbscript >> get date - 1 day

by Richard Mueller [MVP] » Thu, 20 Dec 2007 23:08:22 GMT

I run VBScript programs at a command prompt, at least to troubleshoot them.
If there is an error the message indicates the line number, which is a big
help. You can use Notepad or the Edit command to create a text file and save
a script. It just need to have the extension vbs. Create the file test.vbs
and write in the file this one line:

Wscript.Echo "Yesterday was: " & Date() -1

Save this as test.vbs, then at the command prompt enter the command:

cscript test.vbs

I hope this helps.

Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

vbscript >> get date - 1 day

by Dr J R Stockton » Fri, 21 Dec 2007 01:35:38 GMT

In microsoft.public.scripting.vbscript message <OA7VMGpQIHA.1188@TK2MSFT
NGP04.phx.gbl>, Wed, 19 Dec 2007 23:50:25, "Pegasus (MVP)"
< XXXX@XXXXX.COM > posted:

That's not quite true. Read alt.msdos.batch.nt to find how it has
already been done; or ask there. Also, stepping Y M D back one day at a
time, or N days, is not unduly difficult.

JScript will also do it; and is more capable than VBScript. But VBS is
ample for this need.

See sig.

(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20 ; WinXP.
Web <URL: http://www.merlyn.demon.co.uk/> ; - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL: http://www.merlyn.demon.co.uk/programs/00index.htm> ;
My DOS <URL: http://www.merlyn.demon.co.uk/batfiles.htm> ; - also batprogs.htm.

vbscript >> get date - 1 day

by Pegasus (MVP) » Fri, 21 Dec 2007 03:16:55 GMT

I am fully aware of the methods and I have tried them myself.
They involve formulae like these to calculate Julian dates:

if %m% LSS 3 set /a m=%m%+12 & set /a y=%y%-1
set /a z=-719560+ %d% + (153 * %m%-2) / 5 + 365 * %y% + %y% / 4 - %y% / 100
+ y / 400

In my book this is a little more involved than writing

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

vbscript >> get date - 1 day

by ekkehard.horner » Fri, 21 Dec 2007 05:20:59 GMT

Hassan schrieb:
As I always have problems to remember the order of the parameters
to the DateDiff() function or whether it's String( "-", 20 ) [wrong]
or String( 20, "+" ) [correct], a feature like the "-e" option for
Perl or an interactive shell for VBScript was always on my wishlist.
So I really feel sympathy for Hassan's trusting approach. By rights,
it should have worked!

There are some at least useable scripts at


vbscript >> get date - 1 day

by Dr J R Stockton » Fri, 21 Dec 2007 21:21:57 GMT

In microsoft.public.scripting.vbscript message <#YcHjzzQIHA.1204@TK2MSFT
NGP03.phx.gbl>, Thu, 20 Dec 2007 20:16:55, "Pegasus (MVP)"
< XXXX@XXXXX.COM > posted:

Of course. But you put "write your own", which does not have the same
meaning as "copy someone else's".

Please note that VBScript cannot, unaided, determine true Julian Dates,
because they change, by definition, at noon GMT. It can determine
Chronological Julian Date, which changes at midnight local time. But
CJD is currently 2454456 and the above expression yields something much
smaller - about 13868 I think, so that's something like Chronological
Modified Julian Date or Chronological Truncated Julian date but with an
origin not normally used in the Outside World. Yes, today is indeed
Chronological UNIX 13868 - no valid connection with a Julius.

I presume you know that fly.com is owned by Flycor in Hawaii?

(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL: http://www.merlyn.demon.co.uk/> ; - w. FAQish topics, links, acronyms
PAS EXE etc : <URL: http://www.merlyn.demon.co.uk/programs/> ; - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Similar Threads

1. getting date from day/month/year dropdowns

2. date one day to date function

3. date field generates date plus 30 days

I'm creating a form which will generate two letters.  The first letter needs 
a date field and the second letter needs a calculated date field of first 
letter date plus 30 days.  I found this: Selection.InsertBefore 
Format(((Date+30), "MMMM d yyy")
This only worked the first time we tested, the 30 day date never updated.  

4. getting nonworking days using VB

5. How to get Week Day from Date using VB.Net

6. Subtract Days from a Date

7. Number of days between 2 dates...

I want to work out the difference (number of days) between 2 dates selected 
using the date picker in vb.net and displaying this in textbox1 (which will 
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in practice, 
but appears to always through up 0 in textbox1???  Am I doing anything 
blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?


8. Date from Number of Days - VB.Net