Android Question Date conversion

Sergey_New

Well-Known Member
Licensed User
Longtime User
The application receives dates from an external source in the format "dd MMM yyyy". For example, "12 MAY 1920".
When converting a date
B4X:
DateTime.DateFormat="dd MMM yyyy"
Log(DateTime.DateTimeParse(DateTime.Date("12 MAY 1920"),"02:00:00"))
an error occurs due to the fact that the month name must be "May".
What can be done to make the process case-insensitive?
 
Solution
You need to change the Date/Time output Format to display both:
B4X:
DateTime.DateFormat="dd MMM yyyy"
Dim L As Long = DateTime.DateTimeParse("12 MAY 1920","02:00:00")

DateTime.DateFormat="dd MMM yyyy HH:mm:ss"
Log(DateTime.Date(L))

stevel05

Expert
Licensed User
Longtime User
Edit Explaination:
The error is occurring because you are incorrectly parsing the date before passing it to DateTime.DateTimeParse.
DateTime.DateTimeParse requires 2 Strings
Try:

B4X:
    DateTime.DateFormat="dd MMM yyyy"
    Dim L As Long = DateTime.DateTimeParse("12 MAY 1920","02:00:00")
    Log(DateTime.Date(L))
    Log(DateTime.Time(L))
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I need to get ticks from "12 MAY 1920"
B4X:
Dim L As Long = DateTime.DateTimeParse(DateTime.Date("12 MAY 1920"),"02:00:00")
and not separately date and time
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You need to change the Date/Time output Format to display both:
B4X:
DateTime.DateFormat="dd MMM yyyy"
Dim L As Long = DateTime.DateTimeParse("12 MAY 1920","02:00:00")

DateTime.DateFormat="dd MMM yyyy HH:mm:ss"
Log(DateTime.Date(L))
 
Upvote 0
Solution

Sergey_New

Well-Known Member
Licensed User
Longtime User
Dim L As Long = DateTime.DateTimeParse("12 MAY 1920","02:00:00")
Thank you, it works!
Tell me if it is possible not to specify the time "02:00:00". I don't need it.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, just do:
B4X:
    DateTime.DateFormat="dd MMM yyyy"
    Dim L As Long = DateTime.DateParse("12 MAY 1920")
    Log(DateTime.Date(L))
 
Upvote 0
Top