mac007 Posted June 16, 2009 Share Posted June 16, 2009 Hi, all: I have this problem, where I want to be able to insert a date that's coming from url-variable, like this... www.site.com/page.php?name=john&date=06152009 Also, as you see, the date-variable format comes as month, day, year. So how can I insert this date into my mysql db table? I can usually insert current times into my table with functions like NOW(), and other similar stuff, but how do I grab this variable and make it possible to insert back into my DATE field in my table?? thanks!! appreciate any help... Link to comment https://forums.phpfreaks.com/topic/162417-solved-how-to-insert-date-read-from-url-variable-into-database-date-field/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 16, 2009 Share Posted June 16, 2009 substr is probably the fasted method to get the three different parts out of the GET variable. Link to comment https://forums.phpfreaks.com/topic/162417-solved-how-to-insert-date-read-from-url-variable-into-database-date-field/#findComment-857292 Share on other sites More sharing options...
mac007 Posted June 16, 2009 Author Share Posted June 16, 2009 Hi, PFM... thanks for the tip! it worked beautifully! This is the code I used if it helps anybody... <?php $newdate = $_GET['startdate']; $newdateMonth = substr($newdate,0,2); $newdateDay = substr($newdate,2,2); $newdateYear = substr($newdate,4,4); $newFinalDate = $newdateYear . "-" . $newdateMonth . "-" . $newdateDay; echo $newFinalDate; ?> the final echo line is what I used to populate my hidden "date" form field... which inserts the date into my table's DATE field. Link to comment https://forums.phpfreaks.com/topic/162417-solved-how-to-insert-date-read-from-url-variable-into-database-date-field/#findComment-857318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.