How do I do timestamp conversion? |
[eluser]Volkof[/eluser]
Hi guys, Playing with the format of datetime is one of the most irritating thing in programming, for how I feel. My database has stored a value : Code: 2013-01-08 20:08:34 When I retrieve it and display in View, I want it to become: Code: 8th Jan 2013, 8:08pm I searched through the web. There are so many ways but none of them seems to fit my criteria and it just confuses me Hope that someone can enlighten me Thanks in adv
[eluser]PhilTem[/eluser]
1) What did you try? 2) What did you get? 3) What did you expect to get? Anyway, it's quite simple. You should want to follow the examples on http://php.net/manual/en/datetime.construct.php, so you can solve your problem
[eluser]Aken[/eluser]
- DateTime and related PHP classes - Convert the timestamp into a Unix time in your SQL query. - Convert the timestamp to Unix via PHP's strtotime(). - Use date() to modify the Unix timestamp into whatever you need. Lots of options.
[eluser]Volkof[/eluser]
Hi thanks for the reply. Now I faced another problem. I realized that when I have a field which has a date that uses ON UPDATE CURRENT_TIMESTAMP in phpmyadmin, it saves the time in America (I think) timezone, which is 15 hours behind of my country's timezone. I can't use Code: date_default_timezone_set('Asia/Singapore') Is there anyway I can set the phpmyadmin timezone? Or a workaround method to increment the time by 15 hours upon retrieval? I searched through and found something like you need SUPER privilege to set timezone, which I am not. |
Welcome Guest, Not a member yet? Register Sign In |