South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
Thanks dyanamo. The string manipulation works. This way I can get the month and day as well. Super!
Kloon, is there an equivalent for the MONTH and DAY? Your example works well to get the YEAR.
I have already implemented the substring method.
Just curious why the sql function doesn't work.
I do not see a problem with extracting the string.
The php is running on a Linux server and AFAIK (I may be wrong), the format in a Date field in MySQL is always YYYY-MM-DD.
Only time there will be problem, is when my host (LunarPages) starts to stuff around with the date format on their webservers.
Do you know why.....
SELECT YEAR(TheDate) AS TheYear, MONTH(TheDate) AS TheMonth, DAY(TheDate) AS TheDay FROM MyTable
..... doesn't work.
I'm not changing the date format on the server..... the string will work for now.
The TheDate field is of type 'Date' in the MySql table.
SELECT YEAR(TheDate) AS TheYear FROM MyTable ....works fine
SELECT MONTH(TheDate) AS TheMonth FROM MyTable .... works fine
SELECT DAY(TheDate) AS TheDay FROM MyTable ... works fine
The problem comes when I attempt to get all three values in on SELECT statement.
SELECT YEAR(your_date) Y, MONTH(your_date) M, DAY(your_date) D FROM your_table;
SELECT EXTRACT(YEAR FROM your_date) AS Y, EXTRACT(MONTH FROM your_date) AS M, EXTRACT(DAY FROM your_date) AS D FROM your_table;
Mmmmm.... I retyped the procedure from scratch at home tonight. Sql query works fine with all three in the SELECT.
Will have to drink more coffee at the office.
Thanks everyone for the help.... (and persistency to do it the PROPER way)
Why are you so against doing things properly? Code like this (substring-ing a year out of a date) rubs me up the wrong way...
OOH! I absolutely hate substringed dates. In SQL Server, datediff and dateadd are your best friends...
Where were you yesterday when I was fighting the good fight?![]()