Solved

Need help converting time and date stamp to vbscript now format for datediff comparison

Posted on 2008-10-06
6
566 Views
Last Modified: 2012-06-27
I have an Antivirus program that sets a registry key with a time and date stamp in this format:
01-10-2008 00-31-41 which is:
DD-MM-YYYY HH-MM-SS

I want to use the vbscript function datediff to compare that with the now() time so I can figure out if how old my AV databases are and how long ago the last full scan was ran.

I don't think the time format above is a standard format.  Please provide a code sample that will help me with the datediff.

Thank you!
0
Comment
Question by:jamie177
6 Comments
 
LVL 4

Expert Comment

by:jindalankush
Comment Utility
i think,
u hv to cast date in ur required  formate ,then use datediff function
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
as an example...
strDate = "01-10-2008 00-31-41"

arrData = split(strDate, "-")

dd=arrData(0)

mm=arrData(1)

yy=Left(arrData(2),4)

hh=Right(arrData(2),2)

nn=arrData(3)

ss=arrData(4)
 

newDate=cDate(mm & "/" & dd & "/" & yy & " " & hh & ":" & nn & ":" & ss)
 

wscript.echo newDate

wscript.echo dateDiff("d",newDate,now)

Open in new window

0
 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
You can also use DateSerial+TimeSerial to build VbDate.
This way makes it internationally aware.

Private Sub Form_Load()

   Dim strDate

   Dim arrData
 

   strDate = "01-10-2008 00-31-41"

   arrData = Split(Replace(strDate, " ", "-"), "-")
 

   newDate = DateSerial(arrData(0), arrData(1), arrData(2)) + TimeSerial(arrData(3), arrData(4), arrData(5))
 

   wscript.echo newDate

   wscript.echo DateDiff("d", newDate, Now)

End Sub

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
Correction.
   strDate = "01-10-2008 00-31-41"

   arrData = Split(Replace(strDate, " ", "-"), "-")
 

   newDate = DateSerial(arrData(2), arrData(1), arrData(0)) + TimeSerial(arrData(3), arrData(4), arrData(5))
 

   wscript.echo newDate

   wscript.echo DateDiff("d", newDate, Now)

Open in new window

0
 

Author Comment

by:jamie177
Comment Utility
Thanks gents, I'm going to work on this and see what works for me and will close up the questions soon.

-Jamie177
0
 

Author Closing Comment

by:jamie177
Comment Utility
Thank you sirbounty!  Perfect, just what I was looking for!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

10 Experts available now in Live!

Get 1:1 Help Now