Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2008, 03:14 AM
0x90 0x90 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 5 0x90 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 47 sec
Reputation Power: 0
Date format windows shell script

Hello, I wrote a small batch file that will print today and yesterday date to be used in anther application. problem is with yesterday date, if the date is between 1 to 9 it will print it with out "0", i mean like "2008119" instead of printing it as "20081109".

this is the script:

Code:
@echo off

REM Set Date format
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%
echo today is %date%

REM define yesterday date
set /A dd=%dd%-1
set Pdate=%yyyy%%mm%%dd%
echo yesterday was %Pdate%

exit


any idea ?

Reply With Quote
  #2  
Old November 13th, 2008, 01:11 AM
0x90 0x90 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 5 0x90 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 47 sec
Reputation Power: 0
for work around i used if-else:


Code:
@echo off

REM Set Date format
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%
echo today is %date%

REM define yesterday date
set /A dd=%dd%-1

IF %dd% LSS 10 (

		set Pdate=%yyyy%%mm%0%dd%

	) ELSE (
		set Pdate=%yyyy%%mm%%dd% 
		
	)
	
	echo yesterday was %Pdate%

exit

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Date format windows shell script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap