Due to the fact, that the requested timezone UTC is not mentioned in all of the answers here, I'd like to state another set of solutions for different database vendors.
Especially, the current answers here does not state the correct solution for Oracle.
<changeSet logicalFilePath="my_changeset.xml"
id="1"
author="me"
dbms="mariadb,h2">
<addColumn tableName="MY_TABLE">
<column name="MY_ZONED_DATE_TIME_COLUMN"
type="timestamp(6)"
defaultValueComputed="now()">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
<changeSet logicalFilePath="my_changeset.xml"
id="1"
author="me"
dbms="postgresql">
<addColumn tableName="MY_TABLE">
<column name="MY_ZONED_DATE_TIME_COLUMN"
type="timestamp(6)"
defaultValueComputed="timezone('UTC', now())">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
<changeSet logicalFilePath="my_changeset.xml"
id="1"
author="me"
dbms="oracle">
<addColumn tableName="MY_TABLE">
<column name="MY_ZONED_DATE_TIME_COLUMN"
type="timestamp(6)"
defaultValueComputed="sys_extract_utc(systimestamp)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
(One may use properties, like showed in Dominika's answer, but we had some really bad experiences with properties in liquibase.)
Summary:
now()
is fine for MariaDB, MySql and H2v
now()
is not completely fine for H2, I just got a correct result starting the h2 database with UTC like jdbc:h2:mem:./my_database;TIME ZONE=UTC
(h2database in version 2.x needed). Then now()
is working for sure.
- I'm not sure about
current_timestamp
on PostgreSQL, but timezone('UTC', now())
works. :)
- In Oracle,
sysdate
(mentioned in a few other answers here) is not enough, see as well "How to get UTC value for SYSDATE on Oracle", but sys_extract_utc(systimestamp)
does the trick.