PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tiresome
Forum Newbie
Posts: 16 Joined: Sun Apr 18, 2004 9:45 am
Post
by tiresome » Mon Apr 19, 2004 8:46 am
This is how I created my table in MySql
create table guestBook
(
entry_id integer not null auto_increment,
name varchar(40) null,
location varchar(40) null,
email varchar(40) null,
url varchar(40) null,
comments text null,
created timestamp,
remote_addr varchar(20) null
, key guestbook_key (entry_id)
);
The problem is the created part(ie. timestamp) is displayed like this:
20040420214302
I am actually displaying the records using PHP. Is there a way of formatting the timestamp so that it's more readable?
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Mon Apr 19, 2004 8:49 am
Change the mysql field to int(10) and you can then store the unix epoch time - number of seconds since 1970 - time(); - You can then call the value from the database and do many things with it using the pre-defined php functions.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Apr 19, 2004 8:52 am
kettle_drum wrote: Change the mysql field to int(10) and you can then store the unix epoch time - number of seconds since 1970 - time(); - You can then call the value from the database and do many things with it using the pre-defined php functions.
...or set it to timestamp data type
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Mon Apr 19, 2004 8:58 am
dont forget the DATE_FORMAT function in mysql =)
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Apr 19, 2004 9:04 am
liljester wrote: dont forget the DATE_FORMAT function in mysql =)
You can't use DATE_FORMAT with timestamps as far as i am aware!?
Mark
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Mon Apr 19, 2004 9:06 am
or you can pull stuff with it using substr() - look it up at php.net
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Apr 19, 2004 9:11 am
magicrobotmonkey wrote: or you can pull stuff with it using substr() - look it up at php.net
What you mean
Mark
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Mon Apr 19, 2004 9:16 am
Code: Select all
<?php
$year = substr("20040420214302", 0, 4);
$month = substr("20040420214302", 4, 2);
$day = substr("20040420214302", 6, 2);
echo "$day/$month $year";
?>[/php_man]
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Apr 19, 2004 9:18 am
ah, ic.
The number he is using isn't a proper unix timestamp, just the years, month etc concenated together.
Mark
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Mon Apr 19, 2004 9:22 am
I know thats why if he wants to do it like that he has to manually extract data!
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Mon Apr 19, 2004 10:11 am
Bech100 wrote: liljester wrote: dont forget the DATE_FORMAT function in mysql =)
You can't use DATE_FORMAT with timestamps as far as i am aware!?
Mark
you can, this is how i use time in my sites
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Apr 19, 2004 10:16 am
depends what type of timestamp it is. You can only use it with a MySQL timestamp, not a UNIX timestamp.
Personally, i always use UNIX timestamps
Mark
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Mon Apr 19, 2004 10:20 am
Bech100 wrote: depends what type of timestamp it is. You can only use it with a MySQL timestamp, not a UNIX timestamp.
Personally, i always use UNIX timestamps
Mark
yeah im talking about a MySQL timestamp, i never used to do it this way but i seem to of adopted it for quickness
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Mon Apr 19, 2004 10:24 am
liljester wrote: dont forget the DATE_FORMAT function in mysql =)
...or UNIX_TIMESTAMP
SELECT UNIX_TIMESTAMP(anydatefieldtype);
...then use PHP functions on it. Just a different approach...