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 8162571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:45:37+00:00 2026-06-06T18:45:37+00:00

I need to convert a date and time (GMT) into a timestamp with php.

  • 0

I need to convert a date and time (GMT) into a timestamp with php. The following code shows what I’m currently using:

<?php
$date="2012-06-29 10:50";
$timestamp = strtotime($date);
echo $timestamp;
?>

However, when I test the timestamp in an online convertor (http://www.epochconverter.com), the resulting date is 29th June 2012, 8:50 GMT, or 2 hours previous. Is it possible that the strtotime() function isn’t completely accurate and is just an estimate of the time? If so, are there better methods I could use for getting the exact time?

Thanks.

  • 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-06T18:45:39+00:00Added an answer on June 6, 2026 at 6:45 pm

    strtotime assumes that you are converting a string in your server’s local time, so if the servers time zone is two hours out the result will be as wll.

    The comments in the manual suggest a couple of solutions, you can append UTC to your date:

    $timestamp = strtotime($date.' UTC');
    

    Or you can change the default timezone for the script (this will apply to all other time functions!):

    date_default_timezone_set('UTC');
    $timestamp = strtotime($date);
    

    As a final alternative, you could try date_create_from_format which allows you to specify what exactly the format your string is:

    $datetime = date_create_from_format('Y-m-d H:i', $date, new DateTimeZone('UTC'));
    
    $timestamp = date_format($datetime, 'U');
    // Alternatively (thanks Herbert) - 5.3+ only
    $timestamp = date_timestamp_get($datetime);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do convert RSS feed publish date-time (GMT) to Unix timestamp using PHP? I
I need to convert a Joda-Time DateTime into a String, in the following format:
I have a date that I need to convert using PHP date. I've tried
I need to convert date/time in a text file into number of minutes elapsed
I need to know how to convert a date time of GMT time zone
I'm using Kohana 3.1 and need to convert a date 2011-04-21 into format like
I have the following date/time: 2011-09-27 13:42:16 I need to convert it to: 9/27/2011
I need to convert epoch timestamp to date and time. I have used the
I need to convert the following format into a new format using NSDateFormatter. 'Fri,
I need to convert a timestamp string to java.util.Date . E.g.: MMDDYYHHMMSS to MM-DD-YY

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.