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

  • SEARCH
  • Home
  • 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 8763793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:52:02+00:00 2026-06-13T15:52:02+00:00

How would I go about getting a timestamp in php for today at midnight.

  • 0

How would I go about getting a timestamp in php for today at midnight. Say it’s monday 5PM and I want the Timestamp for Monday(today) at midnight(12 am) which already has happened.

Thank you

  • 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-06-13T15:52:03+00:00Added an answer on June 13, 2026 at 3:52 pm
    $timestamp = strtotime('today midnight');
    

    or via a DateTime:

    $date = new DateTime('today midnight');
    // or: $date = date_create('today midnight');
    $timestamp = $date->getTimestamp();
    

    and then perhaps immutable:

    $midnight = new DateTimeImmutable('today midnight');
    // or: $midnight = date_create_immutable('today midnight');
    $timestampOfMidnight = $midnight->getTimestamp();
    
    1. That is in the default timezone.
    2. Spoiler: just "midnight" or or just "today" return the same.
    3. Add a timezone, e.g. "UTC today", to have it, always.
    4. Spoiler #2: UTC greeting style: "midnightZ"
    5. History: midnight is since PHP 5.1.2 (Jan 2006), today since PHP 4.3.1 (Feb 2003)

    More examples:

    given the time UTC 2020-01-01 00:00:00:

    UTC time is ............: [red   ] 1577836800
    

    when calling strtotime($), results are:

    today midnight .........: [pink  ] 1577833200
    midnight ...............: [pink  ] 1577833200
    today ..................: [pink  ] 1577833200
    tomorrow ...............: [green ] 1577919600
    UTC today ..............: [red   ] 1577836800
    today Z ................: [red   ] 1577836800
    Asia/Shanghai today ....: [lime  ] 1577808000
    Asia/Shanghai ..........: [blue  ] 1577811600
    HKST today .............: [copper] 1577804400
    

    Online Demo: https://3v4l.org/KWFJl


    PHP Documentation:

    • On the Relative Formats page, see the Day-based Notations table. These formats are for strtotime(), DateTime and date_create().

    • You might want to take a look what more PHP has to offer: https://php.net/datetime – the entry page to date-time related functions and objects in PHP with links to other, date-time related extensions.


    NOTE: While "midnight" being technically between two days, here it is "today" (start of day) with PHPs’ strtotime.

    Discussion:

    In so far, the answer strtotime("today midnight") or strtotime("midnight today") is a complete and well sounding answer for PHP, it may appear a bit verbose as strtotime("midnight") and strtotime("today") return the same result.

    But even being more verbose not always instantly answers the question if it is about the Midnight for start of day or the Midnight for end of day even today is given as context. We may think about the start of day when reading "today midnight", but this is an assumption and not precise and perhaps can’t be. Wikipedia:

    Though there is no global unanimity on the issue, most often midnight is considered the start of a new day and is associated with the hour 00:00.

    Compare with this programming question:

    • Given midnight is a time transition
    • When asking for a single UNIX timestamp
    • Then there is no answer

    (it would be between two UNIX timestamps, so you would take two timestamps and describe what the two mean and this would not answer the question as it asks for a single timestamp).

    This is not easy to completely resolve because of this mismatch and by how UNIX Time references date/time.

    Lets take the well known, digital 24-hour clock with hours and minutes and express midnight (is it more precise?):

    $midnight = strtotime("today 00:00");
    

    or for end of day:

    $midnight = strtotime("today 24:00");
    

    (NOTE: shown as start of next day)

    Or the 12-hour clock, it can also be used to give the UNIX Timestamp of today at midnight:

    $midnight = strtotime("12:00 a.m.");
    

    (NOTE: the "12 midnight" notation is not supported by strtotime())

    The confusion that can result of a transition time like Midnight to map on a clock may even become more visible with the 12-hour clock as similar to "midnight" the midday (not available in PHP as a relative date/time format but "noon") is technically between again (now between two full dates at noon, or between the first and the second half of a day).

    As this adds up, the code is likely not well received over a 24 hour clock or just writing out "today midnight".

    Your mileage may vary.

    This is kind of aligned with clock time. From Wikipedia Midnight:

    "Midnight is the transition time from one day to the next – the moment when the date changes, on the local official clock time for any particular jurisdiction. By clock time, midnight is the opposite of noon, differing from it by 12 hours. [bold by me]"

    and from the Wikipedia 12-hour clock:

    "It is not always clear what times "12:00 a.m." and "12:00 p.m." denote. From the Latin words meridies (midday), ante (before) and post (after), the term ante meridiem (a.m.) means before midday and post meridiem (p.m.) means after midday. Since "noon" (midday, meridies (m.)) is neither before nor after itself, the terms a.m. and p.m. do not apply. Although "12 m." was suggested as a way to indicate noon, this is seldom done and also does not resolve the question of how to indicate midnight."

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I go about getting the date of say the 32 Wed of
How would i go about getting the value of a field in another language
How exactly would one go about getting an OpenGL app to run fullscreen straight
http://t-webdesign.co.uk/new/ How would i go about getting the grey div (#content_right) to expand to
Just a quick question about how you would go about implementing this. I want
How would I go about getting the new posts of a subreddit in JSON?
How would I go about getting an array of all the files in a
So i got the database.objects.all() and database.objects.get('name') but how would i got about getting
How would I go about getting the Windows user credentials from a Swing application?
How would I go about getting a string from a UITextField in the iPhone

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.