Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mysql - Datetime in PHP Script

I use a PHP script for a banlist that fetches the date and time, but I have an error and don't know how to convert it to "normal" time.

It lists me only the date : 01.01.1970 um 00:00 Uhr

The script part from this:

//Convert Epoch Time to Standard format
$datetime = date("d.m.Y \u\m H:i \U\h\r", $row['expires']);
echo "<td>$datetime</td>";

This is the entry from the mysql db: http://fs1.directupload.net/images/141208/9ugjslm8.jpg

Dont know if it helps?

Have anyone an idea to solve this?

LINK: http://pastebin.com/r0dXg8FX

  • The row comes from an plugin. for example: $row['name'] , $row ['banner'], $row['reason'] this comes all from the plugin
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It lists me only the date : 01.01.1970 um 00:00 Uhr

That simply means you are thinking of $row['expires'] incorrectly. That is not a UNIX Timestamp value and is producing an invalid date. It means the value essentially evaluates to 0, which is Jan 1st 1970 in UNIX time

date() requires you to send a valid Unix timestamp to it (INT 11), is that what you have in database for that field? or it is a date time field?

Try this

echo date("d.m.Y \u\m H:i \U\h\r", "2014-10-12");   //invalid

echo date("d.m.Y \u\m H:i \U\h\r", time());  //valid: current unix timestamp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...