Date Format Error, Please help

  • Thread starter Thread starter Bernard
  • Start date Start date
B

Bernard

Hello,

Can someone please help me?



We have developed a asp.net application which is working fine on 4 other
computers. We have recently deplyed the application to the live environment
running windows 2000 service pack 4, .NET v1.1.



We continue to get the following error "Cast from string "18/07/2003" to
type 'Date' is not valid." as the date is dmy and not mdy. We tried to
change the server's regional settings to Australia. This did not fix the
problem. We then tried to reinstall the framework. Still no luck.



Is there some setting I have to change on the server or on the framework to
use dmy date format?

Below is an example of the asp.net source that is a corse of the problem.
Please note that it is working on other servers and the work effort to
change the code is not an option:



Public Sub deletepdf(ByVal serverpath As String)
Dim fd As System.IO.DirectoryInfo
Dim fsArray As System.IO.FileInfo()
Dim i As Integer

fd = New System.IO.DirectoryInfo(serverpath + "/Temp")
fsArray = fd.GetFiles()

For i = 0 To fsArray.Length - 1
If (CDate(Format(fsArray(i).CreationTime, "dd/MM/yyyy")) <
CDate(Format(Now(), "dd/MM/yyyy"))) Then
fsArray(i).Delete()
End If
Next i

End Sub



Please help me.



Regards,

Bernard.
 
hi !

you don't need to convert the date to string and back to date if you want to
compare them ...

i would replace this line :
If (CDate(Format(fsArray(i).CreationTime, "dd/MM/yyyy")) <
CDate(Format(Now(), "dd/MM/yyyy"))) Then

by this one:

If fsArray(i).CreationTime < Today() Then

Since the Today() function only returns the Day/Month/Year part of the date
(and not the hours/minutes/seconds part) it's perfect for your test...
And it will work with any culture...
 
Back
Top