FORMATDATETIME produces incorrect hour

35 views
Skip to first unread message

Savannah Durbin

unread,
May 15, 2019, 9:58:58 AM5/15/19
to H2 Database
Seeing an issue where the output of FORMATDATETIME appears to be incorrect for a particular value:

SET @date = '2019-03-10 02:00:00';
SELECT FORMATDATETIME(@date, 'yyyy-MM-dd HH:mm:ss'), YEAR(@date), MONTH(@date), DAY(@date), HOUR(@date);
FORMATDATETIME(@DATE, 'yyyy-MM-dd HH:mm:ss')  YEAR(@DATE)  MONTH(@DATE)  DAY(@DATE)  HOUR(@DATE)  
2019-03-10 03:00:0020193102


The hour is being output as "03" instead of the expected value of "02".

I'm running FORMATDATETIME for every hour of the year 2019, and only see this issue happening for one specific date in 2019 as far as I can tell: 2019-03-10 02:00:00.

I also tried for the year 2020, and a different date produces the incorrect output:

SET @date = '2020-03-08 02:00:00';
SELECT FORMATDATETIME(@date, 'yyyy-MM-dd HH:mm:ss'), YEAR(@date), MONTH(@date), DAY(@date), HOUR(@date);
FORMATDATETIME(@DATE, 'yyyy-MM-dd HH:mm:ss')  YEAR(@DATE)  MONTH(@DATE)  DAY(@DATE)  HOUR(@DATE)  
2020-03-08 03:00:002020382


I am running version 1.4.197 (also tried on 1.4.199).

Evgenij Ryazanov

unread,
May 15, 2019, 11:11:06 AM5/15/19
to H2 Database
Hello.

It looks like your timezone has a DST transition from 2019-03-10 02:00:00 to 2019-03-10 03:00:00, so timestamp 2019-03-10 02:00:00 is not valid. This function always normalizes such timestamps.

You can use the TIMESTAMP WITH TIME ZONE data type to avoid issues on DST boundaries.

SET @date = TIMESTAMP WITH TIME ZONE '2020-03-08 02:00:00 -07';

Savannah Durbin

unread,
May 15, 2019, 2:07:33 PM5/15/19
to H2 Database
Ah, that makes sense. Thanks!
Reply all
Reply to author
Forward
0 new messages