1

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
4
  • 4
    What does your $row['expires'] contains? var_dump() it and see if it's timestamp. Commented Dec 8, 2014 at 8:00
  • Are you sure that the row contains an actual date in the database? I think it's probably just zero which is 1970. Commented Dec 8, 2014 at 8:00
  • 1
    That means $row['expires'] is a value that is essentially 0, the start of the UNIX epoch, Jan 1st 1970. Commented Dec 8, 2014 at 8:01
  • The row is from the database Commented Dec 8, 2014 at 9:58

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

"Default date" is a weird way to put it. It means the value essentially evaluates to 0, which is Jan 1st 1970 in UNIX time.
If $row['expires'] contains any date string then strtotime($row['expires']) would do the trick.
0

Based on this image (that you have given in deleted answer) you have milliseconds. Divide milliseconds with 1000 to get seconds.

Probably something like this:

$datetime = date('d.m.Y \u\m H:i \U\h\r', $row['expires'] / 1000);

But, if you get year 1970, that means that you are on 32bit machine, and your fetched INT is out of range. In this case you could just cut last 3 numbers with string function substr():

$datetime = date('d.m.Y \u\m H:i \U\h\r', substr($row['expires'], 0, -3));

9 Comments

Ok will try this too if im at home :D
Ok i try it so for now the time is correctly but the date is wrong...?!?! very confused.. now its 11.12.2014 because its 08.12.2014 oO fs1.directupload.net/images/141208/swk8pe2s.jpg
sry but dont know what exactly do you mean with var_dump($row['expires']); ? The time was insert by an spigot plugin that the time sends to the mysql db
This? string(13) "1418279542453"
This timestamp represents 2014-12-11T06:32:22Z. If this is invalid, then you have wrong timestamp stored in your database.
|
0

Convert the date to UNIX timestamp first. Try with -

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

1 Comment

I will try this when im at home

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.