timestamp does not indicate the correct date

Asked

Viewed 210 times

4

I’m working on a CMS for display of the articles, my problem is with the function strtotime() does not indicate the correct date, always indicates 1 March 1970. The Row (phpMyAdmin) of one of article_timestamp is given with the format: ex. 1394220287. What I’m doing wrong?

<span id="date">Publicado  
<?php
    setlocale(LC_ALL, NULL);
    date_default_timezone_set('Europe/Lisbon');
    $timeStamp = $article['article_timestamp'];
    $uppercaseMonth = ucfirst(gmstrftime('%B'));
    echo strftime( '%A, %d de ' .$uppercaseMonth. ' de %Y', strtotime($timeStamp));
?></span>
  • Miguel, can you add to the question an example of one of your timestamp(s)? one of the values you have in the comic book

  • I’ve done the update, thank you

3 answers

4


By the example you’ve added to the question I see that $timeStamp is already a timestamp, then there’s no need for the strtotime().

Use only:

echo strftime( '%A, %d de ' .$uppercaseMonth. ' de %Y', $timeStamp);
//                                                     ^^ - tirei o strtotime()

Example in PHP Fiddle

  • 1

    Thank you very much, it worked

0

You can bring the correct Mysql date/time using the function FROM_UNIXTIME()

SELECT
  FROM_UNIXTIME(article_timestamp, '%W, %d de %M de %Y %h:%i:%s') 
FROM 
  sua_tabela

0

If the date format passed to strtotime() is not valid the function returns false. Use DateTime::createFromFormat() to convert dates to timestamp:

DateTime::createFromFormat('Y-m-d H:i:s', '2014-01-01 12:00:00');
  • Thank you, how would I implode that in my code?

  • I tried, but it’s wrong

Browser other questions tagged

You are not signed in. Login or sign up in order to post.