Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.
×Hi!
I get the wrong date after using FORMAT_DATETIME(timestamp, "dd.MM.YY").
Example two times: 1722459600000 and 1735592400000
The first time is translated correctly and it is "01.08.2024".
But the second time is formatted as "31.12.25" instead of "31.12.24".
I calculated the amount of time between the times: (1735592400000 - 1722459600000) / (1000*60*60*24) = 152 days.
"01.08.2024"+ 152 days should be "31.12.24", but where did this extra year come from?
I tried using Local and TimeZone and it didn't help :(
I found out that the whole thing was in the format "dd.MM.YY", I changed it to "dd.MM.yy" and everything became as it should be
Hi @Alex
Yes, you're right.
It's just that YY (YYYYY) and yy (yyyy) are a bit different.
They both represent a year.
But the main difference is that yy represents the calendar year, while YY represents the week year.
A week year can be different from a calendar year, depending on which day the first of January falls on.
here is a link to ISO week date
Here is an example of results with different formatting:
import java.text.SimpleDateFormat
import java.text.Format
Long dateLong = 1735592400000
convertTime(dateLong)
//Result value:
//[yy format: 30.12.24,
// YY format: 30.12.25]
static List<String> convertTime(long time){
List<String> result = []
Date date = new Date(time)
Format format1 = new SimpleDateFormat("dd.MM.yy")
Format format2 = new SimpleDateFormat("dd.MM.YY")
result << "yy format: " + format1.format(date)
result << "YY format: " + format2.format(date)
return result
}
So it's best to avoid YY formatting and stick to yy when you need to deal directly with calendar dates.
Regards,
Vitali
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.