Jump to content

Converting a custom timestamp to a readable format.


gergy008

Recommended Posts

Hi everyone, I need help with a big big favor.

 

Basically, I made my own custom timestamps for a ban system on my website, When a user is banned a timestamp is recorded in this format:

$ctime=date("ymdHis");

Say for example that $ctime is now 100613164500, I need to convert that to a readable format such as 13/06/2010 16:45:00

 

How would I go about doing that? It is a bit complocated I know, I think it uses reg ex. but I'm not really sure.

 

Thanks in advance!

Link to comment
Share on other sites

Why would you do that? What's the purpose of storing timestamps like that? As you can see that's only causing you problems. You really shouldn't be storing them like that. You can try something like this to do what you ask, but I really suggest you don't do it this way..

 

$ctime = date("ymdHis");
list($year, $month, $day, $hour, $minutes, $seconds) = str_split($ctime, 2);
echo "$day/$month/$year $hour:$minutes:$seconds";

Link to comment
Share on other sites

Why would you do that? What's the purpose of storing timestamps like that? As you can see that's only causing you problems. You really shouldn't be storing them like that. You can try something like this to do what you ask, but I really suggest you don't do it this way..

 

$ctime = date("ymdHis");
list($year, $month, $day, $hour, $minutes, $seconds) = str_split($ctime, 2);
echo "$day/$month/$year $hour:$minutes:$seconds";

 

The way I have it is from the longest period of time to the smallest, So 10 06 13 17 02 00 (y m d H i s)

I can then test $myarr['banend'] > $ctime, Which if returns false I can let the user reactivate thier account.

 

I'm sure there are much easier ways to do it but I'm a dumb kid and put to practise the first thing that comes into mind.

Link to comment
Share on other sites

Why would you do that? What's the purpose of storing timestamps like that? As you can see that's only causing you problems. You really shouldn't be storing them like that. You can try something like this to do what you ask, but I really suggest you don't do it this way..

 

$ctime = date("ymdHis");
list($year, $month, $day, $hour, $minutes, $seconds) = str_split($ctime, 2);
echo "$day/$month/$year $hour:$minutes:$seconds";

 

The way I have it is from the longest period of time to the smallest, So 10 06 13 17 02 00 (y m d H i s)

I can then test $myarr['banend'] > $ctime, Which if returns false I can let the user reactivate thier account.

 

I'm sure there are much easier ways to do it but I'm a dumb kid and put to practise the first thing that comes into mind.

I agree with Daniel. Why couldn't you do that with a normal timestamps? There's no need to convert it to your own format.

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.