Jump to content

Adding Year to TIme


Recommended Posts

I have a given date on a webpage, that I'm scraping to insert into a DB.  The date is in this format:

Sun, Feb 9<br />3:00 PM ET

I need to insert this into the DB in this format:  2020-02-09 15:00:00

It will always be this year...How can I change this data to be inserted correctly?

I'm trying this...and it's inserting as 1969

	$date = 'Sun, Feb 9<br />3:00 PM ET':
$healthy = array("<br />", " ET", "Sun.", "Mon.", "Tue.", "Wed.", "Thu", "Fri.", "Sat.", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$yummy   = array("  ", "2020", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	$date = str_replace($healthy, $yummy, $date1);
	$start = date('Y-m-d H:i:s', strtotime("$date -120 minutes"));


Link to comment
Share on other sites

Looks like you just have to skip some parts

var_dump(new DateTime('Sun, Feb 9 3:00 PM'));


object(DateTime)#1 (3) {
  string(26) "2020-02-09 15:00:00.000000"
  string(16) "Europe/Amsterdam"

then modify() and format().

Edited by chhorn
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.