Solved

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

Posted on 2008-10-06
6
576 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
ID: 22648911
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
ID: 22648918
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
ID: 22650755
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
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.

 
LVL 22

Expert Comment

by:danaseaman
ID: 22650787
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
ID: 22718010
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
ID: 31503355
Thank you sirbounty!  Perfect, just what I was looking for!
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

Suggested Solutions

Title # Comments Views Activity
Removing first 4 characters from date field in csv file 7 32
VB6 - Convert HH:MM into Decimal 8 51
Spell Check in VB6 13 95
how to know if my Checkbox is True in VB6.0? 9 36
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

21 Experts available now in Live!

Get 1:1 Help Now