Welcome Guest, Not a member yet? Register   Sign In
How do I do timestamp conversion?
#1

[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 Sad

Hope that someone can enlighten me Smile
Thanks in adv
#2

[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 Wink
#3

[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.
#4

[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')
because the time is already auto generated when I insert the data, so the time is already set.

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.




Theme © iAndrew 2016 - Forum software by © MyBB