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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:48:30+00:00 2026-05-26T08:48:30+00:00

I am trying to parse date strings without having to manipulate strings and expect

  • 0

I am trying to parse date strings without having to manipulate strings and expect a given format.

I want my user to be able to enter January 2, 2011 or 1-2-11, and still end up with 2011-01-02 12:00:00 to save in a database.

Currently, I have this in place:

$post_date = date("Y-m-d H:i:s", strtotime(stripslashes($_POST['post_date'])));

But it seems strtotime is returning 0, because the datetime ends up as 1969-12-31 17:00:00

What do I need to change?


UPDATE

From php.net:

(PHP 4, PHP 5)

strtotime — Parse about any English textual datetime description into a Unix timestamp.

..I guess not!


I am not trying to strtotime( an array:

if(isset($_POST['post_date'])){
                foreach($_POST['post_date'] as $id => $post_date){
                    print $post_date.'<br />';
                    if(strlen(trim($post_date)) && $post_date !== 'Date posted'){
                        $update_data[$id]['post_date'] = date("Y-m-d H:i:s", strtotime(stripslashes($post_date)));
                    }
                }
            }

Got it working with:

if(isset($_POST['post_date'])){
                foreach($_POST['post_date'] as $id => $post_date){
                    print $post_date.'<br />';
                    if(strlen(trim($post_date)) && $post_date !== 'Date posted'){
                        $post_date = str_replace(',', '', $post_date);
                        $post_date = str_replace('-', '/', $post_date);
                        $update_data[$id]['post_date'] = date("Y-m-d H:i:s", strtotime(stripslashes($post_date)));
                    }
                }
            }

Thanks to multiple contributors. I remove commas and replace hyphens with forward slashes.

  • 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-26T08:48:31+00:00Added an answer on May 26, 2026 at 8:48 am

    From the comments the OP said :

    $_POST[‘post_date’] is actually an array (updating multiple records),
    but an example value would be ‘December 31, 2012’

    You cannot pass a comma in the strtotime arguments alongside time, doing so would always return a 1970-01-01 00:00:00. You have to remove the user generated comma.

    $post_date = date("Y-m-d H:i:s", strtotime(stripslashes("1 January 1927 17:59")));
    echo $post_date; //1927-01-01 17:59:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to reject the parsing (through SimpleDateFormat::parse) of 18:00 from the date format
I'm trying to find a date-string format that will allow me to use Date.parse
I'm trying to parse a date/time string using DateTime.ParseExact . It works everywhere, except
I am trying to parse a date that looks like this: 2010-04-05T17:16:00Z This is
I have a problem. I am trying to convert some strings to date, and
Hi i am trying to parse a string into a java.sql.date Here is what
I am trying to parse a timestamp into a human-readable date string, however, I
I am trying to parse a French date to a DateTime object with no
While trying to transform the date format I get an exception:unparseable date and don't
I am trying to parse an SQL date string (ISO 9075) and that uses

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.