• 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Trying to convert from seconds to date

Okay so I have an array of results from a table, we have a start and end time we are retrieving. the start/end time would look something like this:

1345497551   

Now I'm trying to convert this to a real time, for instance 1345497551 might become 2012/05/09 17:23:12 or something. I've found a few things but none seem to work correctly. one solution I tried, according to what someone was saying on another question on here, was

$createdate = date('H:i:s',$numberofsecs);  

where $numberofsecs was the time pulled in from the array. but this only ever outputs 17:00:00 repeatedly for every time we had available for testing.

How can I go about making this work correctly?

php

Assuming that that's a standard unix timestamp string (seconds since midnight 1/1/1970), then you should be able to use date as you mentioned, but just modify the format string:

echo date('Y/m/d H:i:s', $numberofsecs);

The example you mention where you were always getting 17:00:00 could have been because your test cases were all only datestamps, encoded as timestamps, and having an offset from GMT . . .

  • 11
Reply Report
      • 2
    • When I use the above $numberofsecs I get 2012/08/20 23:19:11. I suspect you have a typo, so you're seeing the result of converting 0 to a date.
      • 2
    • Ahh yes you're right I did have one, thank you! is there any reason, if the $numberofsecs was retrieved today, why it would state the date was 2012/08/20 instead of 2012/09/05? but at least its retrieving the proper thing now, thank you!
    • @user1650459 The most likely explanation is that your source data isn't what you expect it to be. Garbage in, garbage out . . .
      • 1
    • it looks like when I attempt that it does give me a date but its definitely not todays/yesterdays date like it should be. I tried that string with the number from the original post and I got 1969/12/31 17:00:00 echoed out to me. any other suggestions?

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions