0

I use this code in php to generate the current date/time

$time = date("m.d G:i:s T Y");

Now i need to store the value in time in mysql table

However it is show as illegal in my table , that is as 0000-00-00 00:00:00

The datatype used by my column is datetime

Thanks for helping me fix it:)

2 Answers 2

1

You try like this

$time = date("Y:m:d H:i:s");

Because mysql datetime must be in YYYY-MM-DD H:I:S format.. Otherwise the data inserted in that field will be 0000-00-00 00:00:00.

You can refer to these links for more reference

Link 1

Link 2

Sign up to request clarification or add additional context in comments.

1 Comment

i need to store the Timezone abbreviation as well , that's why there is a T in the command
0

use this

date('Y-m-d H:i:s',strtotime($time));

3 Comments

i need to store the Timezone abbreviation as well , that's why there is a T in the command –
Then store that abbreviation in another column. Or store it all as a varchar.
Its not possible to store it in same column...i don't mind changing the data type

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.