Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Date problem for 9/1/2007

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,51443
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Date problem for 9/1/2007
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Date problem for 9/1/2007 - 9/2/2007 3:22:34 AM   
  ChadR

 

Posts: 24
Score: 0
Joined: 8/20/2007
Status: offline
Hi all,

I have a problem I am hoping someone can help me resolve.  My script checks a number of business created logs which contain date strings in this format: MMDDYYYY
Yesterday; September 1st, 2007, my script failed to check a number of logs because it returned the date as 09312007.  Here is the code which obtains this date format for these logs:

dateYesterdayMMDDYYYY=Right("0" & Month(Date),2) & Right("0" & Day(Date - 1),2) & Right("0" & Year(Date),4)

I know why it returned 09312007, but I need to resolve this for the future so it doesn't happen again next month: Notice that the code returns the current month (09,) then the current day minus one (31, because yesterday was the 1st.)  How can set this variable so that it is aware if it is the first day of the month? And not only subtract one from the day but also the month?  I use this variable every day because some of the logs we must check contain the previous days date, but I also want it to work when the 1st of the next month comes.

Anyone have any ideas at all? This is bugging me so bad right now!

Thanks,
Chad

Edit: BTW, I know I could use an if statement to check if today is the 1st, but I am hoping I can resolve this in a simpler way.  I like to know the most efficient ways of doing things :)

< Message edited by ChadR -- 9/2/2007 3:25:39 AM >
 
 
Post #: 1
 
 RE: Date problem for 9/1/2007 - 9/2/2007 3:51:18 AM  1 votes
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ChadR,

use DateAdd():

Dim dtToday     : dtToday     = Date()
Dim dtDayBefore : dtDayBefore = DateAdd( "d", -1, dtToday )
WScript.Echo dtToday, dtDayBefore

Good luck!

ehvbs

(in reply to ChadR)
 
 
Post #: 2
 
 RE: Date problem for 9/1/2007 - 9/2/2007 6:32:15 AM   
  ChadR

 

Posts: 24
Score: 0
Joined: 8/20/2007
Status: offline
ehvbs,

That works perfect!  Thank you very much, exactly what I was looking for.

Chad

(in reply to ehvbs)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Date problem for 9/1/2007 Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts