Android Question java.lang.NumberFormatException: For input string!

NewDD

Member
Hi,

To format dates, I use this code:

B4X:
1. DateTime.DateFormat = "MM-dd"
2. Dim tmp As String = DateTime.Now
3. Dim myDate As String = DateTime.Date(tmp)

If the date now is "2022-09-04 18:58:20.34" this gives me this:

tmp = "2022-09-04 18:58:20.34"
myDate = "09-04"

That's all fine.

The problem is with my SQLite database. The column is called DueDate, it's TEXT type and the date in it stored like this:

row1>>>"2020-03-01 15:28:30.13"

You can see that the date format is "YYYY-MM-DD HH:MM:SS.SS"

I use this code to format it:

B4X:
1. DateTime.DateFormat = "MM-dd"
2. Dim tmp As String = Cursor1.GetString("DueDate")
3. Dim myDate As String = DateTime.Date(tmp)

This gives me this:

tmp = "2020-03-01 15:28:30.13" << read from the database correctly
myDate = "" <<< Gives out the following error:

java.lang.NumberFormatException: For input string: "2020-03-01 15:28:30.13"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)

But I expect it to give me this:

tmp = "2020-03-01 15:28:30.13"
myDate= "03-01"

Help me please. Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Watch the date & time video tutorial: https://www.b4x.com/etp.html

Dim myDate As String = DateTime.Date(tmp)
This line is wrong. DateTime.Date expects a ticks value (long number). You can use DateTime.DateParse to parse a date string into a ticks value, though I'm not sure that it is needed in this case as you already have a string.
 
Upvote 0

NewDD

Member
This line is wrong. DateTime.Date expects a ticks value (long number). You can use DateTime.DateParse to parse a date string into a ticks value, though I'm not sure that it is needed in this case as you already have a string.

That's what I realized later thank you.
 
Upvote 0
Top