B4J Question Problem using DateTime.Date()

Mikelgiles

Active Member
Licensed User
Longtime User
Can someone tell me what I am doing wrong when using DateTime.Date(). I should be logging four different dates but instead each of the calculated dates are the same. I have tried everything I can think of and still having the problem. Even after removing it from the app being written. It has to be something that I am overlooking.

Here is what it is logging. Should be
1485237900000 - 2017/05/24
1477285500000 - 2016/05/24 2017/02/24
1469336700000 - 2016/05/24 2016/11/24
1453615500000 - 2016/05/24 2016/05/24
looks like they are all logging the last one

<code>
Sub AppStart (Form1 As Form, Args() As String)
Dim LatestDate, Date3Mo, Date6Mo, Date12Mo As Long
DateTime.DateFormat = "yyyy/mm/dd"
LatestDate=DateTime.DateParse("2017/05/24")
Log(LatestDate & " - " & DateTime.Date(LatestDate))
Date3Mo = DateTime.Add(LatestDate,0,-3,0)
Log(Date3Mo & " - " & DateTime.Date(Date3Mo))
Date6Mo = DateTime.Add(LatestDate,0,-6,0)
Log(Date6Mo & " - " & DateTime.Date(Date6Mo))
Date12Mo = DateTime.Add(LatestDate,-1,0,0)
Log( Date12Mo & " - " & DateTime.Date(Date12Mo))
End Sub
</code>
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Mikelgiles

Active Member
Licensed User
Longtime User
Off the top of my head, I think Month should be MM not mm.
Thanks, I changed the format to "yyyy/MM/dd" and it works. Nut "YYYY/MM/DD" does not. I dont understand this at all but I sure do thank you for pointing it out. Is the year and day supposed to be in lower case and just the month upper case?
Thanks Don. that explains it very well. My ignorance of Java!
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I dont understand this at all
This is because the date format is case sensitive.
M = Month, but m = minute. y = Year, but Y = Week year

Edit: As explained in the link above, thanks DonManfred
 
Upvote 0
Top