Solved

VBSCRIPT - DATE / DAY minus 1

Posted on 2007-03-29
5
838 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

910 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

22 Experts available now in Live!

Get 1:1 Help Now