Date stored in database one day earlier

Hi,

I am getting this weird issue, where I mark a given day, and the day stored in the db is one day before. So if I mark 1st November, I get 31st October in the db.

Have removed the serverTimeZone connection string attribute and no luck.

Have googled around and seems that the mysql server might be doing adjustments when storing, but finding no easy solution.

Has anybody dealt with this problem before_

Thanks,

Carlos Conti.

Try to debug SQL queries and see what exactly data is being passed to the MySQL. Logging setup is described in the documentation. If the application sends the correct data, then the problem with your DB settings, refer to the documentation for your DB version.

Hi, your Tomcat timezone and MySQL timezone are different. Even if you remove the serverTimeZone parameter, MySQL still runs under the UTC TZ.

You must setup your JVM to run on UTC as well, otherwise you need to setup MySQL with TZ data manually (see: https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html).

The easiest solution is the former. While developing set UTC TZ for tomcat in the file deploy/tomcat/bin/setenv.sh:

CATALINA_OPTS="-Xmx512m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -Dapp.home=\"$CATALINA_BASE/../app_home\""

# Uncomment in case of slow startup on Linux VM
#CATALINA_OPTS="$CATALINA_OPTS -Djava.security.egd=file:/dev/./urandom"

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote"
#CATALINA_OPTS="$CATALINA_OPTS \
#-Djava.rmi.server.hostname=localhost \
#-Dcom.sun.management.jmxremote.port=7777 \
#-Dcom.sun.management.jmxremote.ssl=false \
#-Dcom.sun.management.jmxremote.authenticate=false"
#CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"

JPDA_OPTS="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

CATALINA_OPTS="$CATALINA_OPTS $STUDIO_OPTS"

Remember to re-apply this change every time you re-deploy tomcat (thus deleting the deploy dir).

Bye
Paolo