Solved

VBSCRIPT - DATE / DAY minus 1

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

Expert Comment

by:Chris Dent
ID: 18814911

You're most welcome :)

Chris
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 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