BluwAngel Posted March 1, 2012 Share Posted March 1, 2012 heres the problem i have 3 things in url bar $day $month $year (its important it stays 3 variables in url) i know how to get them but what i need is convert these 3 into 1 value and store it to DATE(it would be good to be date type for later use) type in mysql any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/ Share on other sites More sharing options...
creata.physics Posted March 1, 2012 Share Posted March 1, 2012 I won't creata the code for you, but I'll help you wrap your head around things. There's something I need to understand from you first. You said you can grab the values from the url, that I'm assuming looks like this: http://example.com/?day=1&month=3&year=2012 So using $_GET you can grab these values which you said you already know how to do. $month = $_GET['month']; $day = $_GET['day']; $year = $_GET['year']; // Now you need to combine into one value, easy $date = $month . $day . $year; So what exactly do you need after that? Do you want to convert the date into a timestamp? I need some clarity. Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322686 Share on other sites More sharing options...
BluwAngel Posted March 1, 2012 Author Share Posted March 1, 2012 i need just date, you dont need to create tables thats not problem its just syntax i need to solve it Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322689 Share on other sites More sharing options...
creata.physics Posted March 1, 2012 Share Posted March 1, 2012 I'm sorry but I have no idea how to understand what you just wrote. Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322690 Share on other sites More sharing options...
BluwAngel Posted March 1, 2012 Author Share Posted March 1, 2012 i need store that as date in database and later i have to use it to check is date past(old) or coming(new) i need DATE type so i can simply later use "<" ">" in my code example SELECT * FROM calendar WHERE $event_date < $today Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322691 Share on other sites More sharing options...
creata.physics Posted March 1, 2012 Share Posted March 1, 2012 Well, considering that mysql's DATE format is, YYYY-MM-DD, and if your url is http://example.com/?day=01&m=03&year=2012 Then you shouldn't have any issues. You would combine your required get values into one variable: $date_to_enter_into_database = $_GET['year'] . '-' . $_GET['month'] . '-' . $_GET['day']; And add it into your database. That way it is formatted for mysql's DATE function. Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322693 Share on other sites More sharing options...
BluwAngel Posted March 1, 2012 Author Share Posted March 1, 2012 it works thanks problem solved Quote Link to comment https://forums.phpfreaks.com/topic/258035-date-from-url-to-database/#findComment-1322694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.