Solved

VBSCRIPT - DATE / DAY minus 1

Posted on 2007-03-29
5
828 Views
Last Modified: 2008-03-03
Okay so I have...

TheDay = Day(date)

But how do I i make this return the current day - 1, bearing in mind that if it's the first of the month, it needs to show 31 to represent 31st March.

Thanks,

Andrew.
0
Comment
Question by:andrewmilner
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

Hey Andrew,

You'll love this one ;)

Yesterday = Day(Date - 1)

Or

Today = CDate("01/03/2007")
Yesterday = Today - 1

Which will give you 28/02/2007 (UK date format).

Chris
0
 

Author Comment

by:andrewmilner
Comment Utility
Hi Chris,

Thanks for that.

Day(Date - 1) does indeed give the previous calender day, but when used in conjunction with my full code keeps the month current as expected.

Here's my code that i'm using below.  The format I need to get is 2007-03-28

CODE
-------------------------------------------------------------------------------------------------

      TheYear = Year(date)
      TheMonth = Month(date)
      TheDay = Day(date -1)
      
      If len(TheMonth) = 1 then
            TheMonth = "0" & TheMonth
      end if
      
      If len(TheDay) = 1 then
            TheDay = "0" & TheDay
      end if
            
            TheDate = TheYear & "-" & TheMonth & "-" & TheDay
            TheTime = "T20:00:00.999"
            
            DateTime = TheDate & TheTime
            
            response.write DateTime

--------------------------------------------------------------------------------------------------

I basically need calender date in the format above but for the previous calender day inlcuding month if applicabale.

Cheers.

Andrew.
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 250 total points
Comment Utility

Hey Andrew,

That's an odd way to do it.

Why don't you calculate Yesterday before you pull it apart?

Yesterday = Date - 1

TheYear = Year(Yesterday)
TheMonth = Month(Yesterday)
TheDay = Day(Yesterday)

Which also neatly gets you around the New Year.

Chris
0
 

Author Comment

by:andrewmilner
Comment Utility
That's Amazing!

Many thanks Chris, works a treat.
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

You're most welcome :)

Chris
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now