JP128 Posted December 17, 2006 Share Posted December 17, 2006 How would I create a column in a table that adds the date into the field with the current time? And then how would I output it into a format like DD/MM/YYY HH:MM Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/ Share on other sites More sharing options...
JasonLewis Posted December 17, 2006 Share Posted December 17, 2006 just create a table field as a 'datetime' then when inserted the date insert it as now().ie:[code=php:0]$query = mysql_query("INSERT INTO `table` (`datetime`) VALUES (now())");[/code] Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142743 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Then use the mysql DATE_FORMAT() function to format it however you like on the way back out. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142744 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 ok, i thought that I had it solved... but I dont... When I pull the date from the database, and try to format it, it goes to like Dec 31, 1969 4:33:00 pm Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142785 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 does anyone know how to format something like $row['date']? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142800 Share on other sites More sharing options...
BillyBoB Posted December 17, 2006 Share Posted December 17, 2006 this is wat happens to me ... :( Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142801 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 are you getting the same exact time tho? Billy? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142810 Share on other sites More sharing options...
BillyBoB Posted December 17, 2006 Share Posted December 17, 2006 http://dreamshowstudios.net thats wat im getting on home page not in shout idk why shout works ?? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142811 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 Ok, I saw your site... I wonder what is going on there.... but btw, your site is neat. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142815 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 [quote author=JP128 link=topic=118934.msg486495#msg486495 date=1166335040]ok, i thought that I had it solved... but I dont... When I pull the date from the database, and try to format it, it goes to like Dec 31, 1969 4:33:00 pm[/quote]Are you sure you've got a datetime field in the database and not just a time field? It sure looks like its only time. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142825 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 `date` varchar(50) is what the row is.. what should I change it to? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142828 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 datetime Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142830 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 the type instead of varchar? how would i do that? alter table... ? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142832 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 Yeah. phpMyAdmin will let you do it easy enough. Otherwise, there are some ancient incantations you can use but it involves a gallon of bat's blood, and you only get about 2 oz from a typical bat... Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142834 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 lolalthough I dont have phpmyadmin Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142835 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 Date Joined: December 31, 1969, 4:33 pm.... Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-142839 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 anyone know? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143118 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Anyone know what? Use ALTER TABLE to change the field type.[code]ALTER TABLE tblname CHANGE `date` joined_date TIMESTAMP;[/code]PS; Date is a reserved word in mysql so you shouldn't really be using it as a filed name. The above query should change it to [i]joined_date[/i] as well as changing the data type. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143143 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 [code]$time = $row['joined_date'];$newTime= date("m/d/Y h:i:s",$time); echo "Name: " . $row['firstname'] . " " . $row['lastname'] . "<br>";echo "User: " . $row['username'] . "<br>";echo "E-Mail: " . $row['email'] . "<br>";echo "B-Day: " . $row['dob'] . "<br>";echo "Status: " . $row['rank'] . "<br>";echo "Date Joined: ". $newTime . "<br>";[/code]it comes out like Date Joined: 12/31/1969 04:33:26 Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143161 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Did you change the field type? You [i]may[/i] also need to fix your timestamp as they where broken by using the wrong filed type. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143170 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 ALTER TABLE users CHANGE `date` joined_date TIMESTAMP;mysql_query("insert into users values('','$firstname','$lastname','$email','$username',md5('$password'),'$dob','2',now())") or die(mysql_error()); 19 //ID firstnametest //Firstname lastnametest //Lastname emailtest //email usernametest //Username 81dc9bdb52d04dc20036dbd8313ed055 //MD5 Password 01-01-1900 //DoB 3 // Rank 2006-12-17 15:07:37 //Date Joined Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143183 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Problem solved then. Please mark the thread as such. Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143187 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 its not solvedthat is what is in the database... the output is 12/31/1969 4:33:26 Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143190 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Is there only one record in this database? Are you sure the results are for the record you showed the insert code for? The rank is also different.PS; I may as well ask you now, but that dob field, is it varchar aswell? Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143196 Share on other sites More sharing options...
JP128 Posted December 17, 2006 Author Share Posted December 17, 2006 there are a few in the table... I have it call those rows from the table where the username is = to $_SESSION['username'] Link to comment https://forums.phpfreaks.com/topic/30938-solved-inserting-date-into-mysql/#findComment-143197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.