troubleshooting Question

PHP Date Formatting

Avatar of MarthaJ Sayers
MarthaJ Sayers asked on
Microsoft SQL ServerPHPSQL
15 Comments1 Solution163 ViewsLast Modified:
I am using PHP v 5.6.25 and MS SQL Server 2014. I have a column that is defined as a datetime. I am extracting data and this is what the data looks like that I am trying to format and insert into this column:

 Wed, 20 Nov 2019 18:21:05 -0500

I was able to extract the following:

20 Nov 2019 18:21:05

 and then was able to turn it into this:

 11/20/2019 18:21:05

But I need it in 12 hr format and I know the format needs to be this (I think)

$date = new DateTime($wrkRecvDate);

The above produces this:

2019/20/11 6:06:21:05

which is exactly what I wanted HOWEVER it will not insert into my
table - I have attached a image of the error message.
 I am using a sql insert statement and I have tried with/without enclosed with quotes and it will not work.
If I just use the date portion and drop the time, the record will insert just fine.
I have also tried this as to formatting:
$date = new DateTime($wrkRecvDate);
 echo $date->format('Y/d/m   g:h:i:s')
which produced this:2019/20/11 6:06:21:05 - again, exactly what I needed but will not insert into the column.
Any help would be appericiated.

David Johnson, CD
The More I know, the more I don't know
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros