0

Is there a simple function to convert the the datetime2 format to output correctly using PHP?

I'm able to get a correct date, but the time always returns as 00:00:00, despite showing correctly on the database.

I'm using the following to output the date/time;

echo $row['OrderDate']->format('d/m/Y H:i:s');

I have tried various suggested solutions without any success (perhaps they only work on datetime, not datetime2?)

Not sure if this is relevant, but the field is set with a precision of 19 and length of 6 in datetime2 format.

The data appears like so in the SQL;

2020-07-13 09:00:48

Any advice would be greatly appreciated!

Dale K
  • 25,246
  • 15
  • 42
  • 71
user1235285
  • 87
  • 2
  • 17
  • _... the field is set with a precision of 19 and length of 6 in datetime2_ - what is the actual definition for the `OrderDate` column? And what driver do you use to connect to SQL Server? – Zhorov Aug 03 '20 at 07:38
  • OrderDate datetime2 NOT NULL Using PDO (mysql, sqlite, pgsql, sqlsrv) to connect to MS SQL – user1235285 Aug 03 '20 at 07:53
  • I'm not able to reproduce this issue using: 1) `CREATE TABLE DateTime2Table (OrderDate datetime2); INSERT INTO DateTime2Table (OrderDate) VALUES ('2020-07-13T09:00:48')` and 2) PHP Driver for SQL Server and `new PDO("sqlsrv:server=$server;Database=$database", $username, $password);`. If possible, post your full PHP code. More explanations about retrieving datatime values can be found [here](https://stackoverflow.com/questions/61350489/data-type-differences-between-php-sqlsrv-driver-and-pdo-driver/61352482#61352482). Thanks – Zhorov Aug 03 '20 at 08:40

0 Answers0