473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Weekend date for given a date

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.
Nov 12 '05 #1
7 13323
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
Nov 12 '05 #2
I think DAYOFWEEK function will help you, pls ref. to SQL Reference 1.

"AdityaK" <ad*******@gmail.com> ????
news:63**************************@posting.google.c om...
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.

Nov 12 '05 #3
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" <ad*******@gmail.com> ????
news:63**************************@posting.google.c om...
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.

Nov 12 '05 #4
AdityaK wrote:
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.


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
Nov 12 '05 #5
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.
Nov 12 '05 #6
to*****@jp.ibm.com (Tokunaga T.) wrote in message news:<81**************************@posting.google. com>...
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.


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
Nov 12 '05 #7
to*****@jp.ibm.com (Tokunaga T.) wrote in message news:<81**************************@posting.google. com>...
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.


Thanks a lot... I was able to get Weekend date (Saturday's date) using
above query....
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Barry Warsaw | last post by:
The current mail.python.org machine has had many problems over the last few weeks, and it's time to move. Also, we have a deadline of 06-Jul-2004 before ZopeCorp and Baymountain decommission the...
2
by: AdityaK | last post by:
Is there anyway I can get weekend date for a given date using DB2 query? I couldn't find any DB2 function that can be used to do so. Thanks, Aditya
2
by: Joey Martin | last post by:
I have a sql database and ASP pages. How do I find out the DATES of THIS WEEKEND (fri-sun). If today is Tuesday, I want to show information posted for THIS WEEKEND. My table has a field...
3
by: darnnnel | last post by:
Hey guys, i have this code: SELECT * FROM QueryCases WHERE Weekday(QueryCases.StartDate) In ('1','7') AND QueryCases.Completed = False ORDER BY QueryCases.StartDate; the WHERE...
6
by: ysoussov | last post by:
Hey does anyone know of an easy script to use to figure out whether the current date is a weekend or not, i currently have a script that returns the current date and time. Also it would be great if...
30
by: Paul W Smith | last post by:
I have written a hit counter, which I believe counts the times my page is hit by a user for each unique session by the user. The relevant part of my code is below: If...
3
by: buddyr | last post by:
Hello, I have a form. When a user enters item number Date shipped field is filled with current date. TurnAroundTime is a number field to add the number of days to Date shipped. DatOut is an...
7
by: Mike | last post by:
I have a routine that's calculating business days but its not counting the weekend days that are between the start date and end date. If my start date is 9/26/08 and my end date is 10/01/08, I...
4
by: welshboi | last post by:
Hi all, long time reader, first time poster :D I've got a page i've put together in javascript, and one of the fields takes the date (in dd/mm/yyyy) format. What I'm trying to do, is if a user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.