![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table with 3 columns YearNo, WeekNo, DayNo Is there any syntax I can use in a Query to return the date (yyyy-mm-dd) from these values? |
#3
| |||
| |||
|
|
On 21 Nov 2011 in comp.databases.mysql, R C Nesbit wrote: I have a table with 3 columns YearNo, WeekNo, DayNo Is there any syntax I can use in a Query to return the date (yyyy-mm-dd) from these values? STR_TO_DATE() should do it, given an appropriate format string. http://dev.mysql.com/doc/refman/5.1/...on_str-to-date |
#4
| |||
| |||
|
|
http://dev.mysql.com/doc/refman/5.1/...on_str-to-date Hmmm, I was thinking of a combination using date_add(), but this is a much better solution. |
|
However, I would also recommend the op change his table to use a single DATE type column. It's quite easy to extract the year, week and day of week from this value. And it ensures the date will always be valid. |
#5
| |||
| |||
|
|
Jerry Stuckle spoke: http://dev.mysql.com/doc/refman/5.1/...on_str-to-date Hmmm, I was thinking of a combination using date_add(), but this is a much better solution. This is what I actually ended up doing in a script. However, I would also recommend the op change his table to use a single DATE type column. It's quite easy to extract the year, week and day of week from this value. And it ensures the date will always be valid. Not so easy, as the table is quite large, need to be accessed very rapidly to update a screen matrix (works schedule) of 7 Weekday rows by n columns, all indexed to the display by wk(screen)& day number (row)& vehicle (column) I hate dealing with dates& times in code - why can't they decimalise it? It would make life *much* simpler! I dread to think what code would be like if we were still using £/-p |
#6
| |||
| |||
|
|
I have a table with 3 columns YearNo, WeekNo, DayNo Is there any syntax I can use in a Query to return the date (yyyy-mm-dd) from these values? |
#7
| |||
| |||
|
|
How big is big? |
|
Have you actually tried it? My experience has been that the date functions are quite fast. And if you're just looking for a single week, you could use the week start and end date in your WHERE clause to limit the initial selection. With an index on the date column, the results should be quite fast. MySQL makes date types easy to work with. gb |
#8
| |||
| |||
|
|
Beware that MySQL supports 8 different types of week numbers (see manual for the week() function), and that you need to use the year that matches the correct type of week numbering. For example, the year associated with 2011-01-01 (which is a Saturday) may be 2010, not 2011, depending on which week-numbering scheme you are using. (There are also some week-numbering systems in use which MySQL does not support, such as weeks beginning on Saturday). |
|
You probably have a lot of existing data, so whatever definition of week numbers you're using, you probably want to stick with. |
![]() |
| Thread Tools | |
| Display Modes | |
| |