It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Send time with form

Moderator: Malcolm

Send time with form

Postby Johnathan on Mon Dec 08, 2008 9:28 pm

I have a form I'm using it for an update thing and I want it to send the time the post is created into the database so I can echo it out again. How do I send the current date into the database?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Re: Send time with form

Postby webmaster on Mon Dec 08, 2008 9:34 pm

If you use MySQL, make a new field and name it to whatever you like, I like to name it "added", set the type (you know like CHAR or INT) to DATETIME

Then when you insert things to the database, you use NOW()

Like this:
Code: Select all
$insert = "INSERT INTO ababab (added,a,b)
VALUES (NOW()'$a','$b')";
mysql_query($insert) or die ("Could not add data to the table");


Note that NOW() shouldn't be surrounded by '
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Re: Send time with form

Postby Johnathan on Mon Dec 08, 2008 9:41 pm

:) Thank you, that worked. Now is there anyway I can echo it out differently? Like 08/12/2008 at 21:40 instead of 2008-12-08 21:39:48?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Re: Send time with form

Postby webmaster on Mon Dec 08, 2008 10:09 pm

Humm, I don't know, I've never needed to do that.

You an use substr() for just removing the last 3 chars of a variable, but that will result in showing 21:39 instead of 21:40, but maybe that doesn't matter?

Otherwise, take a look here:
http://se2.php.net/datetime
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Re: Send time with form

Postby Johnathan on Mon Dec 08, 2008 10:22 pm

Yea, I was looking at that earlier and I don't really need the time. It's only the date that is really needed.
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Re: Send time with form

Postby webmaster on Mon Dec 08, 2008 10:30 pm

Alright, try using substr() then, that's really simple to use.
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden


Who is online

Users browsing this forum: No registered users and 0 guests