Skip to content

Fix: SQL queries using NOW() rely on MySQL timezone instead of shop timezone#41596

Closed
mattgoud wants to merge 1 commit into
PrestaShop:9.1.xfrom
mattgoud:fix-30828-replace-sql-now-with-php-date
Closed

Fix: SQL queries using NOW() rely on MySQL timezone instead of shop timezone#41596
mattgoud wants to merge 1 commit into
PrestaShop:9.1.xfrom
mattgoud:fix-30828-replace-sql-now-with-php-date

Conversation

@mattgoud

@mattgoud mattgoud commented Jun 2, 2026

Copy link
Copy Markdown
Contributor
Questions Answers
Branch? 9.1.x
Description? Several SQL queries used NOW() to compare or store the current date, which relies on the MySQL server timezone (UTC by default). This caused issues when the shop's configured timezone differs from the MySQL server's timezone — for example, a cart rule valid from a given hour would not appear to customers until MySQL's UTC clock reached that hour.

This PR replaces all core occurrences of NOW() in raw SQL queries with PHP's date('Y-m-d H:i:s'), which always uses the shop's configured timezone (set via date_default_timezone_set). The affected files are CartRule.php (2 occurrences — the primary bug), ProductSale.php (3 occurrences), Connection.php (1 occurrence) and Product.php (1 occurrence).
Type? bug fix
Category? FO
BC breaks? no
Deprecations? no
How to test? 1. Set your shop timezone to Europe/Paris (or any timezone different from UTC).
2. Ensure your MySQL server runs in UTC (default).
3. Create a cart rule for a specific customer with a date_from set to the current time.
4. Log in on the FO with that customer and go to My account > My vouchers.
5. The cart rule should appear immediately (before the fix it would only appear 1–2 hours later depending on DST).
UI Tests
Fixed issue or discussion? Fixes #30828
Related PRs This is the surgical, low-risk fix targeting the maintained stable branch 9.1.x (merges up into develop). The broader connection-level approach for develop/9.2 — which aligns the MySQL session time zone with the shop time zone on every connection and covers all NOW() at once — is #41628. The two do not conflict (idempotent, no file overlap); see #41628 for the full comparison. Native module PRs from the same effort: PrestaShop/ps_googleanalytics#177, PrestaShop/blockwishlist#451, PrestaShop/ps_emailsubscription#127, PrestaShop/ps_facetedsearch#1234, PrestaShop/pagesnotfound#42, PrestaShop/statssearch#30, PrestaShop/statsbestproducts#28
Sponsor company PrestaShop SA

@mattgoud mattgoud requested a review from a team as a code owner June 2, 2026 09:57
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jun 2, 2026
@ps-jarvis ps-jarvis added Bug fix Type: Bug fix 9.1.x Branch labels Jun 2, 2026
@mattgoud mattgoud added this to the 9.1.4 milestone Jun 2, 2026
@mattgoud mattgoud changed the base branch from 9.1.x to develop June 2, 2026 12:20
@mattgoud mattgoud requested a review from a team as a code owner June 2, 2026 12:20
@github-actions github-actions Bot modified the milestones: 9.1.4, 9.2.0 Jun 2, 2026
@mattgoud mattgoud force-pushed the fix-30828-replace-sql-now-with-php-date branch from 359a7a3 to 14b0a04 Compare June 2, 2026 12:25
@mattgoud mattgoud added develop Branch and removed 9.1.x Branch labels Jun 2, 2026
@mattgoud mattgoud added the Bug Type: Bug label Jun 2, 2026
@mattgoud mattgoud self-assigned this Jun 2, 2026
@mattgoud mattgoud force-pushed the fix-30828-replace-sql-now-with-php-date branch from 14b0a04 to 118da1c Compare June 4, 2026 11:09
@mattgoud mattgoud changed the base branch from develop to 9.1.x June 4, 2026 11:10
@github-actions github-actions Bot modified the milestones: 9.2.0, 9.1.5 Jun 4, 2026
@ps-jarvis ps-jarvis added 9.1.x Branch and removed develop Branch labels Jun 4, 2026
Replace all occurrences of NOW() in raw SQL queries with PHP's date('Y-m-d H:i:s')
so that the shop's configured timezone (PHP) is always used instead of the MySQL
server's timezone (UTC by default).

Fixes PrestaShop#30828

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mattgoud mattgoud force-pushed the fix-30828-replace-sql-now-with-php-date branch from 118da1c to fbb2b6a Compare June 4, 2026 12:41
@mattgoud

mattgoud commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Closed. Alternative solution proposed by the PR #41628 (nb: targets the develop branch only)

@mattgoud mattgoud closed this Jun 5, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Closed in PR Dashboard Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

9.1.x Branch Bug fix Type: Bug fix Bug Type: Bug

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

Some SQL queries use NOW() which uses the mysql timezone (UTC) and not the shop timezone

2 participants