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.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Structure does not convert time to date correctly

Alex
Contributor
December 25, 2024

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 :(

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Alex
Contributor
December 25, 2024

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

Vitali Basarevski December 30, 2024

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

TAGS
AUG Leaders

Atlassian Community Events