Timestamps

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Splui
Forum Newbie
Posts: 2
Joined: Sun Oct 12, 2003 3:04 pm

Timestamps

Post by Splui »

In the following example the field name is a string and date is of type datetime.

A query, SELECT name, date FROM sometable returns a result set. This is placed in $result and accessed via $info=mysql_fetch_array($result).

A while loop takes each field in turn and places them in local variables $name and $date respectively.

The $date seems to be giving me a timestamp of just the year (ie e.g. 2002-01-11 00:00:00 gives the timestamp 2002) which, when used via the date() function, always gives Jan 1, 1970 1.33am.

A straight output of $date shows the correct full date and time but I want to format the output.

Any ideas how to get the full timestamp?

Much obliged

splui
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

select unix_timestamp(date_col) from your table..
will give you the time stamp of date and then you can convert it into you own format ...
for more information refer to mysql date time functinon ..
Splui
Forum Newbie
Posts: 2
Joined: Sun Oct 12, 2003 3:04 pm

Post by Splui »

Worked a treat, thanks a lot!!

splui
Post Reply