[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBSCRIPT - DATE / DAY minus 1

Posted on 2007-03-29
5
Medium Priority
?
996 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 71

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 71

Accepted Solution

by:
Chris Dent earned 1000 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 71

Expert Comment

by:Chris Dent
ID: 18814911

You're most welcome :)

Chris
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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