dbTalk Databases Forums  

Get date from Year Week Day?

comp.databases.mysql comp.databases.mysql


Discuss Get date from Year Week Day? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
R C Nesbit
 
Posts: n/a

Default Get date from Year Week Day? - 11-21-2011 , 06:50 AM






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?

--
Rob

Reply With Quote
  #2  
Old   
Joe Makowiec
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-21-2011 , 07:57 AM






On 21 Nov 2011 in comp.databases.mysql, R C Nesbit wrote:

Quote:
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

--
Joe Makowiec
http://makowiec.org/
Email: http://makowiec.org/contact/?Joe
Usenet Improvement Project: http://twovoyagers.com/improve-usenet.org/

Reply With Quote
  #3  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-21-2011 , 08:42 AM



On 11/21/2011 8:57 AM, Joe Makowiec wrote:
Quote:
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

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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #4  
Old   
R C Nesbit
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-21-2011 , 01:44 PM



Jerry Stuckle spoke:
Quote:
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.

Quote:
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

--
Rob

Reply With Quote
  #5  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-21-2011 , 02:10 PM



On 11/21/2011 2:44 PM, R C Nesbit wrote:
Quote:
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

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

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #6  
Old   
Gordon Burditt
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-22-2011 , 04:56 PM



Quote:
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?
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.

You can do this conversion with str_to_date(), using %x, %X, or %Y
(and hopefully *not* %y) for the year, %U, %u, %V, or %v for the
week number, and %w for the day of the week. You need to use the
correct conversions for the year and week number based on which set
of week numbers you are using.

Reply With Quote
  #7  
Old   
R C Nesbit
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-23-2011 , 01:02 PM



Jerry Stuckle spoke:
Quote:
How big is big?
Not huge - at present around 50k records.
But the screen is set to refresh every 60 seconds for people with read-only
privilege since several people with write access can be updating it at
once.
The screen is a matrix of 7 x nn and each cell can have x records in it.
so it works fine with querying on year & week, and the dayno (row) &
anotherID (column) gives me the coordinates to fill the matrix.

Now there is a requirement to give a date value for any given record. My
own fault for not foreseeing this, so I've added a date column as well and
written a script to convert the Y-W-D fields into a julian date.

Quote:
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

Reply With Quote
  #8  
Old   
R C Nesbit
 
Posts: n/a

Default Re: Get date from Year Week Day? - 11-23-2011 , 01:02 PM



Gordon Burditt spoke:
Quote:
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).
Yes I know - tiz a right pain!

Quote:
You probably have a lot of existing data, so whatever definition
of week numbers you're using, you probably want to stick with.
Correct - oddities of week 0 and week 53 are handled in code as
exceptions. Thankfully the user doesn't do much work between Dec24 -
Jan2.

--
Rob

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.