× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks DB. So it is going from Monday to Sunday - meaning for dates from
10/7/24 (Monday) to 10/13/24 (Sunday), it will return 10/7/24.

Vinay

On Tue, Oct 29, 2024 at 11:27 AM Dsternb <dieter.bender@xxxxxxxxxxxx> wrote:

<Vinay>
I have been asked to convert some SQL server SQLs to DB2 SQLs. I am not
sure what the following SQL is doing and how to convert it. I THINK it is
getting the date for the Monday of this week. Even if it is true, I don't
know how to do it in DB2 SQL.

UPDATE DIVTOPRCSS SET EAS_START_DT = CONVERT(VARCHAR (10),DATEADD(DAY,
DATEDIFF(DAY, 6, GETDATE())/7* 7, 0), 126) WHERE ISSUEID IN ('109452',
'1099999', '1100000')
</Vinay>

open a sql window to MS SQL Server (SQirreL or DBeaver) you could check:

select getdate() -> retrieves current timestamp
select DATEDIFF(DAY, 6, GETDATE()) -> is going back 6 days, shoing
internal number of the date
select DATEDIFF(DAY, 6, GETDATE())/7*7 -> is going back to monday before
select DATEADD (DAY, DATEDIFF(DAY, 6, GETDATE())/7*7 , 0) -> same as last
before (adding 0 days is doing nothing)
select CONVERT(VARCHAR(10), DATEADD (DAY, DATEDIFF(DAY, 6, GETDATE())/7*7 ,
0), 126) -> converts to varchar(10) with default internal length of 126

the resulting value is put into the update statement

D*B



--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.