deceptikon
Challenge Accepted
3,460 posts since Jan 2012
Reputation Points: 822
Solved Threads: 474
Skill Endorsements: 57
$ts; // timestamp value
echo date('j-n-Y h:i:s a', $ts);
diafol
Keep Smiling
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
The date() function takes two arguments. The first argument specifies the date format you want the timestamp to be converted to. The second argument specifies the timestamp that will be converted. Without the second argument, how does the date() function know what the date is?
deceptikon
Challenge Accepted
3,460 posts since Jan 2012
Reputation Points: 822
Solved Threads: 474
Skill Endorsements: 57
Sorry GR. I'm totally lost with regard to what you're trying to do. This unix timestamp - are you storing it in the DB? The 'normal' date format - what's happening with this - from your code it looks as though you're storing this. Could you rephrase your needs / use maybe?
diafol
Keep Smiling
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
OK, store datetimes either as unix timestamp (INT) or datetime (DATETIME) - which will be in the Y-m-d H:i:s format. DO NOT store date/times in custom format if you can avoid it. Searching and comparing dates is then very difficult.
You can use a number of different php functions, e.g. date() to format a timestamp for display purposes.
If you want to insert a unix timestamp, you have a couple of options:
$time = time(); // and then insert this
OR
INSERT INTO ... `ts` = UNIX_TIMESTAMP()
diafol
Keep Smiling
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
using NOW() only displays the year, thanks for the input though. I have no idea why these commands are not executing propperly.
You may have set your INT size in your Table FIELD to too small a number for the timestamp field. Leave the size blank for now.
ok getting the unix timestamp into the DB is easy i had that before, what about translating it to normal format when it is retrieved from the server so you dont see just millions of seconds displayed? which is the orrigional question I had asked.
Yes bu t you then showed the code which totally tries to do the opposite of what you're asking.
You extract the timestamp from the DB:
$ts = $row['timestamp'];
Or whatever you're using, then
echo date('j-n-Y h:i:s a', $ts);
As I originally posted.
diafol
Keep Smiling
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Question Answered as of 3 Months Ago by
diafol,
deceptikon
and
EvolutionFallen