sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
AdityaK's Avatar

Weekend date for given a date


Question posted by: AdityaK (Guest) on November 12th, 2005 09:37 AM
Is there a way to find Weekend date for a given date using a DB2
query? I see that there are scalar functions such as DAY, DAYOFMONTH,
DAYOFWEEK,etc are available...but couldn't find one to get a weekend
date for any given date. Any information is appreciated.

Thanks,
Aditya.
7 Answers Posted
Serge Rielau's Avatar
Guest - n/a Posts
#2: Re: Weekend date for given a date

Not sure how you define weekenddate, but thsi litle function will give
you the last saturday or today if today is saturday:

create function saturday(d date)
returns date
contains sql deterministic no external action
return case when dayofweek(d)<7 then d - dayofweek(d) days else d end

Enjoys
Serge
Hardy's Avatar
Guest - n/a Posts
#3: Re: Weekend date for given a date

I think DAYOFWEEK function will help you, pls ref. to SQL Reference 1.

"AdityaK" <adityakum@gmail.com> ????
news:6399aa1e.0410261437.52dac07b@posting.google.c om...[color=blue]
> Is there a way to find Weekend date for a given date using a DB2
> query? I see that there are scalar functions such as DAY, DAYOFMONTH,
> DAYOFWEEK,etc are available...but couldn't find one to get a weekend
> date for any given date. Any information is appreciated.
>
> Thanks,
> Aditya.[/color]


Hardy's Avatar
Guest - n/a Posts
#4: Re: Weekend date for given a date

my test:

db2 create table zd( time timestamp)
db2 insert into zd (values current timestamp)
db2 select date(time)+(7-dayofweek(time)) days from zd

pls try.

"AdityaK" <adityakum@gmail.com> ????
news:6399aa1e.0410261437.52dac07b@posting.google.c om...[color=blue]
> Is there a way to find Weekend date for a given date using a DB2
> query? I see that there are scalar functions such as DAY, DAYOFMONTH,
> DAYOFWEEK,etc are available...but couldn't find one to get a weekend
> date for any given date. Any information is appreciated.
>
> Thanks,
> Aditya.[/color]


Knut Stolze's Avatar
Guest - n/a Posts
#5: Re: Weekend date for given a date

AdityaK wrote:
[color=blue]
> Is there a way to find Weekend date for a given date using a DB2
> query? I see that there are scalar functions such as DAY, DAYOFMONTH,
> DAYOFWEEK,etc are available...but couldn't find one to get a weekend
> date for any given date. Any information is appreciated.[/color]

Do you want to have the Saturday or Sunday? If it is the Sunday, which one
do you want to get? (Note the convention in the US is often that the week
starts on Sunday, whereas it starts on Monday in Europe.)

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Tokunaga T.'s Avatar
Guest - n/a Posts
#6: Re: Weekend date for given a date

How about this?
------------------------------ Commands Entered ------------------------------
SELECT givendate
, givendate + (7-DayOfWeek_ISO(givendate)) DAYS AS Weekend
FROM (VALUES Current Date) AS R(givendate)
;
------------------------------------------------------------------------------

GIVENDATE WEEKEND
---------- ----------
2004-10-27 2004-10-31

1 record(s) selected.
AdityaK's Avatar
Guest - n/a Posts
#7: Re: Weekend date for given a date

Join Bytes! (Tokunaga T.) wrote in message news:<8156d9ae.0410262347.798cddb5@posting.google.com>...[color=blue]
> How about this?
> ------------------------------ Commands Entered ------------------------------
> SELECT givendate
> , givendate + (7-DayOfWeek_ISO(givendate)) DAYS AS Weekend
> FROM (VALUES Current Date) AS R(givendate)
> ;
> ------------------------------------------------------------------------------
>
> GIVENDATE WEEKEND
> ---------- ----------
> 2004-10-27 2004-10-31
>
> 1 record(s) selected.[/color]

Thanks a lot everybody for your response...
I was trying out this query to get SATURDAY's date in that week.
"select column1,column2,rcpt_date,weekenddate(rcpt_date) from ATABLE
where conditions;"
I tried the query in previous response but am getting SQL error:
'SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD CURRENT, TOKEN FULL
LEFT INNER RIGHT WAS EXPECTED'

Thanks,
Aditya K
AdityaK's Avatar
Guest - n/a Posts
#8: Re: Weekend date for given a date

Join Bytes! (Tokunaga T.) wrote in message news:<8156d9ae.0410262347.798cddb5@posting.google.com>...[color=blue]
> How about this?
> ------------------------------ Commands Entered ------------------------------
> SELECT givendate
> , givendate + (7-DayOfWeek_ISO(givendate)) DAYS AS Weekend
> FROM (VALUES Current Date) AS R(givendate)
> ;
> ------------------------------------------------------------------------------
>
> GIVENDATE WEEKEND
> ---------- ----------
> 2004-10-27 2004-10-31
>
> 1 record(s) selected.[/color]

Thanks a lot... I was able to get Weekend date (Saturday's date) using
above query....
 
Not the answer you were looking for? Post your question . . .
196,920 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,920 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors