?
Solved

Comparing string to datetime.

Posted on 2009-02-11
3
Medium Priority
?
264 Views
Last Modified: 2012-05-06
I have the following:

Dim value As String = String.Empty
 value = filename.Substring(4, 11)
                                                 
value = 20090210
I need to compare this to datetime and return true if older than 7 days.
0
Comment
Question by:mathieu_cupryk
  • 2
3 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 23614948
Hi mathieu_cupryk;

This should do what you need.

value = "20090210"

Dim dt As DateTime = New DateTime(Int32.Parse(value.Substring(0, 4)), _
                                  Int32.Parse(value.Substring(4, 2)), _
                                  Int32.Parse(value.Substring(6, 2)))

Dim ts As TimeSpan = dt - Today

If ts.Days > 7 Then
    ' Delete your files in here
End If


Fernando
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23614969
dim dt as new date(value.substring(0,4), value.substring(4,2),value.substring(6,2))
if dt < date.today.adddays(-7) then
    'older then 7 days
endif
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 23615020
Sorry; this line of code

Dim ts As TimeSpan = dt - Today

Should be this:

Dim ts As TimeSpan = Today - dt

Fernando
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

840 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