Unparseable date?

sconlon

Active Member
Licensed User
Longtime User
My app downloads a CSV file from an FTP server and reads a date, eg 27/02/2012, from the first line of the file (I have set the date format to "dd/MM/yyyy") - each line of the file contains 5 fields. It then checks if that date is more than 7 days old using the code below.

Dim dateline(), newdate As String
Dim table1 As List
Dim su As StringUtils

If File.Exists(csvpath,csvFile) Then
table1 = su.LoadCSV(csvPath,csvFile,chrSeparator)
dateline = table1.Get(0)
newdate = dateline(0)
If DateTime.DateParse(newdate) > DateTime.DateParse(curdate) Then

The thing is that when I download the file from one FTP server it works fine but when the same file is downloaded from another server I get a Java.text.ParseException: Unparseable date: "27/02/21012". If I run it in debug mode and check the contents of newdate it seems to be exactly the same in both cases. Any ideas about what could be causing this?

Thanks.
SC
 
The date in your post is unparseable "27/02/21012" not sure if that is your typo or the problem.
 
Upvote 0
There are no spaces in the date but I tried your code anyway but it made no difference - still getting the error. I'm completely puzzled!
 
Upvote 0
So I changed the date to "02/03/2012" and it now works fine. Then changed the date back to 27/02/2012 and it still works. So I don't know what was up with the previous incarnation of that date but there must have been something the parsedate didn't like.

Thanks for the suggestions.
 
Upvote 0
hi erel,

i retrieved a date value from a remote mysql database. the value is shown, let's say "1999-03-26 01:24:16" as an example.
as mysql default format, it simply means 26th march 1999, 01:24:16.

i can use the data as string. but i always get this error "java.text.ParseException: Unparseable date: "1999-03-16 01:24:16" (at offset 4)"
when i use this
Code: Copy
Date1=DateTime.DateParse(DateString)
Time1=DateTime.TimeParse(DateString)

Date1 and Time1 are declared as long, while DateString is declared as string.

is there anyway i can get the date value (in tick or long) and the time value (in thick or long) so i can use it for further date calculation?

or should i use this code?
Code: Copy
DateTime.DateFormat="yyyy-MM-dd"
                DateTime.TimeFormat="HH:mm:ss"
                Date1=DateTime.DateParse(DateString)
                Time1=DateTime.TimeParse(DateString)
               
                'make a string and other date format
                DateTime.DateFormat="dd-MM-yyyy"
                DateString=DateTime.Date(Date1) & ", " & DateTime.Time(Time1)

but the code is still throw me the same error, unparseable date
 
Upvote 0
Try this code:
Code: Copy
Dim DateString = "1999-03-26 01:24:16" As String
Dim DateTimeTicks As Long
Dim Date_Time() As String
Date_Time = Regex.Split(" ", DateString)
DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss"
DateTimeTicks = DateTime.DateTimeParse(Date_Time(0), Date_Time(1))
 
Upvote 0

Similar Threads

Back
Top