lvertel Posted March 19, 2009 Share Posted March 19, 2009 hello people. i have 2 questions : -how to save a date from a html form in mysql database in the dd-mm-yyyy format ?! - i have a website with users being able to publish their concerts. I wish to SHOW in php all the concerts that are about to be HELD, and all concerts that have passed, i would like them to be not showns... is it possible ?? thanks in advance.. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/ Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 Right, well in reply to your first question you can get the date by doing something like this: $date = date('d/m/Y', time()); And your second question, do something like this: <?php $limit = 60 * 60 * 24 * 7; //seven days mysql_query("SELECT * FROM table WHERE date <= '$limit'"); //select from the table where the date held is less than or equal to the limit ?> Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788373 Share on other sites More sharing options...
lvertel Posted March 19, 2009 Author Share Posted March 19, 2009 hello thank you for your reply. Well the fact is that i need to take the date that the USER submits, which can be , e.g. 15.05.2010. how do i put it in the $date with a html form ? Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788385 Share on other sites More sharing options...
lvertel Posted March 19, 2009 Author Share Posted March 19, 2009 hmmm here is my code : $date = date("d-m-y"); then i put it in database , and it comes in this format : 2020-03-09 !!!! it is for sure not the right time..what is happening ?? p.s. my table structure is : type = date, default = 0000-00-00 ....i cant change it... Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788393 Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 That's because you're not applying the current time to it. You need to add time() on the end of the date function, eg time('d-m-Y', time()); And maybe you want to look at the mktime() function? Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788461 Share on other sites More sharing options...
revraz Posted March 19, 2009 Share Posted March 19, 2009 There is no good reason to store your day in that format. Store the date properly YYYY-MM-DD and then display it anyway you choose. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788467 Share on other sites More sharing options...
lvertel Posted March 19, 2009 Author Share Posted March 19, 2009 hello guys, i used this : echo date("d.m.Y",strtotime("$comment_date")); and in the echo i can decide how to OUTPUT the date....simple as that... do you guys know what is the BEST way to store lets say a birthday date in database through a html form ? just looking for an advice Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788473 Share on other sites More sharing options...
revraz Posted March 19, 2009 Share Posted March 19, 2009 The best way to store a Date in a DB is the MySQL format or Unix Format. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788500 Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 I personally store everything as a unix timestamp and then manipulate it with the date() function on display. There's a lot more stuff you can do with a timestamp than you can do with a date format... Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788644 Share on other sites More sharing options...
revraz Posted March 19, 2009 Share Posted March 19, 2009 Like what? There's a lot more stuff you can do with a timestamp than you can do with a date format... Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788808 Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 Like ordering, searching, converting. I just find it easier than having to convert a date back into a timestamp before I can run any fuctions upon it. Why...don't you? Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788811 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Errrr...... Jackpf, I think you misunderstood him. DATE is easier to work with than a unix timestamp most of the time x.x. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788868 Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 ...why? What can you do with a date that you can't do with a timestamp..? Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788978 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Hrmmm, nothing since a unix timestamp can be converted to a DATE. Why have the overhead of conversion though? A lot of stuff requires conversion by the way. Yeah, you can order a unix timestamp, and yeah, you can do ranges calculated in PHP, but some stuff would be too ghetto to do that way. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788991 Share on other sites More sharing options...
Mchl Posted March 19, 2009 Share Posted March 19, 2009 Using unix timestamp for birthday is not good. You know, there are actually people who were born before 1970. Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788994 Share on other sites More sharing options...
revraz Posted March 20, 2009 Share Posted March 20, 2009 That was my point to your comment. There is nothing you can do with Unix Timestamp that you can't do with a MySQL Date/Time. And as pointed out, goes beyond dates before 1970. ...why? What can you do with a date that you can't do with a timestamp..? Quote Link to comment https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-789435 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.