manuelgod Posted February 20, 2007 Share Posted February 20, 2007 I haven't had much experience with php and mysql, so I am asking for help on how to do the following in php: I have 4 fields that I created : start_date varchar(30); comments varchar(200); notify_user varchar(5); birthdate varchar(20); Now SOME records have been filled with the correct values BUT some values in some records have now() as a value instead of the actual data, in this example start_date. I want to change only the values in start_date that have the now() value to an actual date like : 1985/12/30 Can anyone show me a good example script on how to do this ? Thanks in advance guys ! Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/ Share on other sites More sharing options...
hvle Posted February 20, 2007 Share Posted February 20, 2007 What you should change is the data type form start_date and birthdate to date format instead of varchar. Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/#findComment-189913 Share on other sites More sharing options...
manuelgod Posted February 20, 2007 Author Share Posted February 20, 2007 Is there a way to do this in the process? I don't want to delete the db and create a new one ... Thanks Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/#findComment-189922 Share on other sites More sharing options...
hvle Posted February 20, 2007 Share Posted February 20, 2007 Yes you can change the data type anytime. However, you might have to correct the existed values in the table. You can use phpmyadmin or mysql administrator (local server) to do that. The reason why it is better to use date instead of varchar to store date is because with date format, you can do many thing with it, like comparing date, validation date, subtract, add... you name it. It is also much for efficient to query. Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/#findComment-189932 Share on other sites More sharing options...
manuelgod Posted February 21, 2007 Author Share Posted February 21, 2007 Anyone with some sample code please?? Thanks ! Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/#findComment-190104 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 If i understand correctly, you have some fields that were stored with the string "now()" instead of the actual date. I'm pretty sure you can't replace the now() with the date it was supposed to have entered, but you can certainly update it with the current date. Run the sql: "UPDATE `tablename` SET `start_date` = now() WHERE `start_date` = 'now()'" Make sure that when you use now() from now on that it is not contained in quotes. The quotes will make it a string and mysql will store the string "now()" instead of the functions result. Link to comment https://forums.phpfreaks.com/topic/39367-help-with-php-and-mysql/#findComment-190111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.