Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3788662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:02:06+00:00 2026-05-19T12:02:06+00:00

I learnt that I should Store UTC and Show in local time. How can

  • 0

I learnt that I should Store UTC and Show in local time. How can I query the SQL database for rows that are due today, according to user time. I have a Todo table with a column dueOn it contains the UTC Unix Timestamp in int.

I think it will look something like

SELECT * FROM Todos 
WHERE dueOn BETWEEN {today's timestamp} AND {tomorrow's timestamp}

What will I use to get today’s & tomorrow’s timestamp? I think this sounds simple, but I am very confused with all the similar methods for date & time

UPDATE

I am wondering of something like below is correct

// set default timezone to the user's timezone
date_default_timezone_set("Asia/Singapore"); 
// get UTC datetime for today & tomorrow
$today = DateTime::createFromFormat('Y-m-d', date('Y-m-d'), new DateTimeZone('UTC')); 
$tomorrow =  clone($today);
$tomorrow->add(DateInterval::createFromDateString('1 day'));

$sql = 'SELECT * FROM Todos WHERE dueOn BETWEEN ' . $today->getTimestamp() . ' AND ' . $tomorrow->getTimestamp();
echo $sql;

Can I somehow get the user’s time without using date_default_timezone_set? Or will it be allright as that will just set the timezone for the request?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:02:06+00:00Added an answer on May 19, 2026 at 12:02 pm

    In your SQL query, use CONVERT_TZ to convert the due date from the user’s time to UTC.

    Ex:

    SELECT * FROM Todos
    WHERE CONVERT_TZ('2011-01-21', 'EST', 'UTC') BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 DAY)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that extern C means the function should be compiled in C style
For haskell practice I want to implement a game where students/pupils should learn some
I tried to search forum topics to find a tutorial that will guide me
I'm trying to write a macro in Lisp that re-implements let using itself. This
I'd like to know more about the different ways of solving Single Sign-On and
I have a Relational Schema with attributes (A B C D). I have a
I have a small application developed in ASP.NET 2.0 WebForms. For learning purpose, I
I am trying to learn ASP.NET MVC. After reading through many articles on the
What to learn to be able to send files online using c++ on windows
I want to learn the best and most effective way to test my website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.