Weiss Posted September 2, 2017 Share Posted September 2, 2017 Hi. i have a table with a date row. i have 2 problems with it. first, it saves the date as mm-dd-yyyy and i actually need it to save it as dd-mm-yyyy. the second problem is more of a question.. after a date has been saved, can i use it to calculate? can i calculate and output this date + day for example? thanks in advance Link to comment Share on other sites More sharing options...
dsonesuk Posted September 2, 2017 Share Posted September 2, 2017 If you use any of the date types in mysql database it should save it as 'YYYY-MM-DD' only, if you save as text string you should be able to save as you want it. but! IF you wish to do calculations through MYSQL query's it expects the format to be as used by date types, OR if calculation of dates through PHP, it expects if year month and days used be be 'YYYY-MM-DD' formatting type with exception of hyphens where slashes could be used. Of course you could retrieve specific date ref from custom text string date, and put them in correct order for calculation, but that means more work, whereas you could reformat the database date on output to a page. http://w3resource.com/mysql/date-and-time-functions/mysql-weekofyear-function.php 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 2, 2017 Author Share Posted September 2, 2017 Thanks! so correct me if im wrong, by reading your comment, its best to keep the data in database as deafult yyyy-mm-dd so i can have calculations. if my customer want to see it in dd-mm-yyyy i can retreive the data and manipulate it while echoing in the php code? is that what i should do? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 2, 2017 Share Posted September 2, 2017 (edited) Yes! you can easily reformat the date format from database to whatever you want, with whatever separators you want on output using echo, see https://www.w3schools.com/php/showphp.asp?filename=demo_func_date_format https://www.w3schools.com/php/php_date.asp Its just a matter of swapping YY and DD on desired string format parameter Edited September 2, 2017 by dsonesuk 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 2, 2017 Author Share Posted September 2, 2017 You sir, are the best. thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now