gergy008 Posted June 13, 2010 Share Posted June 13, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/ Share on other sites More sharing options...
Daniel0 Posted June 13, 2010 Share Posted June 13, 2010 Why would you create your own "custom timestamp"? Anyways, use DateTime::createFromFormat(). Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/#findComment-1071463 Share on other sites More sharing options...
Alex Posted June 13, 2010 Share Posted June 13, 2010 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"; Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/#findComment-1071464 Share on other sites More sharing options...
gergy008 Posted June 13, 2010 Author Share Posted June 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/#findComment-1071472 Share on other sites More sharing options...
Daniel0 Posted June 13, 2010 Share Posted June 13, 2010 In PHP you would be better off using the DateTime class, and in MySQL by using the DATE or DATETIME data types. Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/#findComment-1071479 Share on other sites More sharing options...
Alex Posted June 13, 2010 Share Posted June 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204649-converting-a-custom-timestamp-to-a-readable-format/#findComment-1071480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.