Jump to content

[SOLVED] Formatting timestamps


Kairu

Recommended Posts

Theres.... a problem?.... Eh... this makes no sense in my mind.

$text = "[" . date("h:ia", $txt[(($i*3)+2)]) . "] " . $text;

When I do it like that, I ALWAYS get 7:33pm.....

When I do it like this:

$text = "[" . $txt[(($i*3)+2)] . "] " . $text;

I get the proper time stored in the variable, only its the very large and bulky timestamp.

Please don't request the code.... It's 19KB large.... But if you ask, I'll give it.
Link to comment
Share on other sites

[code=php:0]$now = '2006-12-31 19:51:21';
function format_time($now) {
$time = explode(' ', $now);
$time[2] = explode('-', $time[0]);
$time[3] = explode(':', $time[1]);

$time = mktime($time[3][0], $time[3][1], $time[3][2], $time[2][1], $time[2][2], $time[2][0]);
$time = date('h:i:s A', $time);

return $time;
}

echo format_time($now);
[/code]

Made this myself, just for you...I think it's what you wanted...
Link to comment
Share on other sites

I can quite easily explain that :P And it wouldent tell you anyway, since it's a database pull.

What txt[] is, is a hell of a lot of rows of data pulled from a database. Every fourth entry in txt[] is a timestamp, regular format. "2006-12-30 10:50:31" is actually one of the entries. But after running through date() as shown above.... it ouputs as 7:33pm (Or, more accurately, in that example with the code, it would look like this:

[7:33pm] Kairu: Test Text

And when not formatted:

[2006-12-30 10:50:31] Kairu: Test Text


Added: Thank you [i]very[/i] much Nhoj. It works quite well! [img]http://graphics4.gaiaonline.com/images/template/smiles/icon_3nodding.gif[/img]
Link to comment
Share on other sites

Um.... Is their any reason that can be seen that would prevent something like this from working?

$output = "<option selected value=\"b\">" . format_time(NOW()) . "</option>";
echo $output;

Actoually this wont work either.....
$output = "<option selected value=\"b\">" . NOW() . "</option>";
echo $output;

They just.... I dunno. They don't output errors or anything, they (Timestamp and formatted timestamp) just.... prevent $output from echoing..... at all.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.