Solved

VBSCRIPT - DATE / DAY minus 1

Posted on 2007-03-29
5
868 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
ID: 18814343

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
ID: 18814629
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
ID: 18814710

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
ID: 18814877
That's Amazing!

Many thanks Chris, works a treat.
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 18814911

You're most welcome :)

Chris
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

837 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