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!

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";

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.