Petty_Crim Posted June 30, 2007 Share Posted June 30, 2007 ATM my database is using an American style date format with the year coming first, then the month then the day, is there a way to set it so it goes day, month, year? Basically how it works is I got 3 drop down boxes with days, months and years in it. The user choose the desired date clicks a button and it updates the db. My problem is its has that American format and if I put it as text then I won't be able to do calculations or sorts on the date so I need it as a date. Also do I need to actually change anything in my mysql data base in regards to the date field atm I got it set as a date is there any additional things I gotta change? Quote Link to comment Share on other sites More sharing options...
metrostars Posted June 30, 2007 Share Posted June 30, 2007 I think there is a way, but that is the basis behind all mysql systems. You'd be better off just formatting the date in the mysql query. eg SELECT DATE_FORMAT(`datecolumn`, '%d/%c/%Y') from ... WHERE ... that would brind the date in the table out inthe form of DD/MM/YYYY. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted June 30, 2007 Author Share Posted June 30, 2007 I see what you mean but my query I'm using is this: $result2=mysql_query("SELECT opponent, map, score, result, date, FROM gamestats WHERE match_id='$match_idP'"); How do I do what you suggested with this query? Quote Link to comment Share on other sites More sharing options...
metrostars Posted June 30, 2007 Share Posted June 30, 2007 $result2=mysql_query("SELECT opponent, map, score, result, DATE_FORMAT(`date`, '%d/%c/%Y'), FROM gamestats WHERE match_id='$match_idP'"); that should work. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted June 30, 2007 Author Share Posted June 30, 2007 Ok that sort of works I got no errors with it but now when I echo out $date it doesn't show anything. I've checked my DB and there is a date stored in the field but for some reason its not outputting it. Quote Link to comment Share on other sites More sharing options...
metrostars Posted June 30, 2007 Share Posted June 30, 2007 o sorry $result2=mysql_query("SELECT opponent, map, score, result, DATE_FORMAT(`date`, '%d/%c/%Y') AS 'date' FROM gamestats WHERE match_id='$match_idP'"); try that one. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted June 30, 2007 Author Share Posted June 30, 2007 Yup that was it works perfectly now. Thx for all your help Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 30, 2007 Share Posted June 30, 2007 I find it easier to store dates in thte american format of yyyy/mm/dd as I can thten order items from the database by date, without having to add extra code. I then 're-arrange' the date if I need to display it to dd/mm/yyyy, but leaving in american format in thte database. Quote Link to comment Share on other sites More sharing options...
metrostars Posted June 30, 2007 Share Posted June 30, 2007 I wouldn't know how if it's possible to change them anyways, i think i once heard someone talking about changing it in some MySQL files, but it seems to complicated. Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted June 30, 2007 Author Share Posted June 30, 2007 I find it easier to store dates in thte american format of yyyy/mm/dd as I can thten order items from the database by date, without having to add extra code. I then 're-arrange' the date if I need to display it to dd/mm/yyyy, but leaving in american format in thte database. Yep thats what this is doing, they are stored in American format in the database but when I show it on screen it comes out as European format. Quote Link to comment 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.