PRENDETEVELO NEL CULO
PRENDETEVELO NEL CULO

Reputation: 133

Why does php's date function return wrongly formatted date?

I want to get the current date via:

date('YYYY-MM-DD hh:mm:ss', time())

but this will return:

2018201820182018-MarMar-WedWed 0909:0303:4949

Why?

Upvotes: 0

Views: 67

Answers (3)

ep_mxl
ep_mxl

Reputation: 41

Try using this instead:

date('Y-M-D h:i:s', time());

See the manual for date, you can see that the 'Y' character already outputs the year in the 4 digit format. The same goes for the other characters.

Upvotes: 0

ishegg
ishegg

Reputation: 9927

You only need to put each letter once:

echo date('Y-M-D h:i:s', time());

Result

2018-Mar-Wed 02:03:27

You can see all the formats and a description in the manual

Upvotes: 4

Partharaj Deb
Partharaj Deb

Reputation: 904

Try this

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

It may seem wrong time if you're in different timezone. In that case you can set required timezone using this function like this before using date() function-

date_default_timezone_set("Asia/Dhaka");

Upvotes: 1

Related Questions