mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2008-12-06, 09:20   #1
IronBits
I ♥ BOINC!
 
IronBits's Avatar
 
Oct 2002
Glendale, AZ. (USA)

3×7×53 Posts
Default vbscript datediff.vbs

If you don't enter an argument, it will take the current system date of your computer and change it from 'Sat 12/06/2008' and change it to 2008-12-06.

Assuming date /t gives you Sat 12/06/2008

cscript /nologo datediff.vbs 1 would show you 2008-12-05
cscript /nologo datediff.vbs 2 would show you 2008-12-04
cscript /nologo datediff.vbs 31 would show you 2008-11-05

Code:
' returns the date for how many days back you need to find the date for in YYYY-MM-DD format.

Option Explicit

Dim strNum, arrDate, strYear, strMonth, strDay, strDate
Dim objArgs

Set objArgs = WScript.Arguments

if WScript.Arguments.Count < 1 then 
    strNum = "0"
Else
    strNum = Wscript.Arguments(0)
End If

arrDate = Split(DateAdd( "d" , -strNum , Date ), "/", -1, 1 )
strYear = arrDate(2)
strMonth = arrDate(0)
strDay = arrDate(1)
if strMonth < 10 then strMonth = "0"&strMonth
if strDay < 10 then strDay = "0"&strDay
strDate = strYear & "-" & strMonth & "-" & strDay

wscript.echo strDate
To use it in a DOS/CMD batchfile
for /f "tokens=*" %%a in ('cscript /nologo datediff.vbs 0') do set MyNewDate=%%a

echo %MyNewDate%
2008-12-06

Last fiddled with by IronBits on 2008-12-06 at 09:23
IronBits is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
vbscript help IronBits Programming 18 2008-11-27 03:02

All times are UTC. The time now is 01:23.

Sat Oct 24 01:23:24 UTC 2020 up 43 days, 22:34, 0 users, load averages: 1.08, 1.24, 1.24

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.