Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Comparing string to datetime.

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.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

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
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
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial