find the day example saturday from date in ssis - ssis

I want to find out the day of the week from date in ssis.
Actually i want to move the data from one server to another,
In the source server there is one cloumn reportdate having the previous date,so while i wan to copy in to the destination server wan to insert todays date,but there is one case like there is no data comes on sunday in the source server in that case i will have the data of saturday so in this case i want to update the date in the destination server with 2 days plus,please let me know how can i reslove this using ssis.i'm using derived column for manipulating the date column DATEADD("day",2,reportdate) : DATEADD("day",1,reportdate),
so first part will update the date plus 2 of the sourcedate into the detsination table date but how will i find the day of week means when the saturday comes...please let me know how can i reslove this using ssis.
Thanks is advance..

Try this :
DATENAME(weekday, GETDATE())== "Sunday" ? DATEADD("day",2,reportdate):
DATEADD("day",1,reportdate)
Use GETDATE() else use DATEADD(day,-1,reportdate) in the above expression
Update :
Use DATEPART in SSIS
DATEPART( "Weekday", getdate())
Expression is
DATEPART("weekday", GETDATE()) == 1 ? DATEADD("day",2,getdate()):DATEADD("day",1,getdate())
The above expression works in my system having SSIS 2008

Related

How get previous day in parameter in SSIS package

I have a package in SSIS when I have a start date with a parameter:
However I have a query then use that parameter, but I need to have de previous day here:
for exemple if start_date is '2022-03-03' I need to set up #SDATE to '2022-03-02'.
Can anyone help me. Thanks
This will give the previous date of the date in question :
(DT_WSTR, 10) DATEADD("day",-1,start_date)

IsWeekEnd Expresion in SSIS that is locale-neutral

How can I write an SSIS expression that determines whether a date is a weekend day?
I have this expression, but it seems it only 'works on my machine'
DATEPART( "Weekday", #[User::CurrentDate] ) ==6 || DATEPART( "Weekday", #[User::CurrentDate] ) ==7
After I deploy SSIS package to server, is suddenly changes order of numbers and
Monday became 2.
When on my computer Monday is 1, exactly as I expected.
I checked SQL Server itself, but it seems is something inside SSIS decide if Sunday or Monday is first day.
I cannot find exact question related to this issue.
Well, if you must do this in an SSIS expression, here is one way to work around the problem: you would compare the DW of your variable to the DW of a known constant (like August 3, 2019, which is a Saturday in any locale that I know of).
In pseudocode, IF ( DW(DateVariable) = DW("20190803") OR DW(DateVariable) = (DW("20190803")+1)%7 ) THEN {DateVariable is a weekend}
Personally, I would look for a way to do this in TSQL. Import the raw data "as is" into a staging table, and then do the transformation while moving the data to the destination table with a stored procedure.
DATEPART("DW",GETDATE()) or DATEPART("WEEKDAY",GETDATE()) works perfectly fine on both SQL server and local.
How are you passing value to #[User::CurrentDate] variable(Please check if same date is set when packages is executed on SQL server and on local)
I changed DateTime on my local and tested your expression as part Of Execute SQL task and Derived Column Transformation which gives me 1 for Sunday, 2 for Monday and so on and the result matches with SQL.
SQL query to get day of week:
SELECT GETDATE() Today,DATENAME("DW", GETDATE()) DayofWeekToday,
DATEPART("DW",GETDATE()) DayNumberToday,GETDATE()-1 Yesterday,
DATENAME("DW", GETDATE()-1) DayofWeekYesterday,DATEPART("DW",GETDATE()-1) DayNumberYesterday
Adding more to my answer : There is a difference between DateFirst and DatePart. DateFirst sets first day of the week while Datepart gives you day of the week. use this sql function to check what's your first day of the week
Set Datefirst 7 -- To set first day of week (7 = Sunday)
SELECT ##DATEFIRST -- To check first day of week
**Update your system settings to match first day of the week with sql server and you should get same values when you evaluate expression.
Your expression looks good its only your first day of week on local and sql server are not matching.
Once I updated first day of week on SQL, I was able to replicate the issue you are facing.

Last sunday of previous week in SSIS

I want a SSIS expression which will give me the sunday date of last week.
Corresponding sql server query looks like :
select convert(date,DATEADD(wk, DATEDIFF(wk, 6, convert(date,#report_dt)), -1))
I want the same result in SSIS expression.
Thanks
Assuming your date is held in a variable called report_dt, this works for me:
(DT_DATE)LEFT((DT_WSTR, 30)DATEADD("Day", -1 * (DATEPART("Weekday", #[User::report_dt]) + 7), #[User::report_dt]), 10)
However not sure if this is region safe - but it works in the UK.
This will give you the Sunday of last week using the variable report_dt:
(DT_DBDATE)DATEPART("dw",#[User::report_dt]) == (DT_DBDATE)1 ? #[User::report_dt] : DATEADD("day",-(DATEPART("dw",#[User::report_dt]) - 1),#[User::report_dt])
It's casted as DT_DBTIME so only the date is returned.

Pulling prior year data

I am working on a query to pull all turnover in the past calendar year that is going to be used daily. Rather than going in and having to change the date each time I would just like to be able to run the query and have it automatically only pull the last 365 days worth of data. The code itself looks like:
SELECT O867IA_VJOBHST.SYS_EMP_ID_NR, O867IA_VJOBHST.REC_EFF_STT_DT, O867IA_VJOBHST.EMP_ACN_TYP_CD
FROM O867IA_VJOBHST
WHERE (((O867IA_VJOBHST.EMP_ACN_TYP_CD)="HIR"));
Where the REC_EFF_STT_DT is the date the ACN_TYP_CD occurred, in this case when they were HIR (Hired)
Any Ideas?
Access SQL provides Date() and DateAdd() functions. You can work out what you need from those functions in the Immediate window ...
? Date()
9/9/2013
? DateAdd("d", -365, Date())
9/9/2012
Then you can filter REC_EFF_STT_DT on the same date range in a query like this ...
SELECT o.SYS_EMP_ID_NR, o.REC_EFF_STT_DT, o.EMP_ACN_TYP_CD
FROM O867IA_VJOBHST AS o
WHERE
o.REC_EFF_STT_DT BETWEEN DateAdd('d', -365, Date()) AND Date();

How to get current month name in SSRS?

I need current month name as default perameter name in my ssrs report. How can I get current month name using an ssrs expression?
For example "27-09-2012" would become "September"
and one more i need....
27-09-2012 to previous month name as well (August)
First question:
=MonthName(Month(Fields!datefield.Value))
Second question:
=MonthName(Month(DateAdd("m", -1, Today())))
I think the second question answer might be something like that, first converting the date to month then subtracting 1 from the month value and then converting it to month name.
Further reading:
SSRS Reports get Month name from Month Index or from date
Converting month number to month name in reporting services
OFF: I would change the date format you are using to 2012-09-27 as it works in every setting and should give you peace of mind when converting date formats.
Don't subtract 1 b/c it won't work for January.
Use this:
MonthName(Month(DateAdd("m", -1, CDate(Today))))
As a note, I tried the suggestion of =MonthName(Month(today())). What I would get is #error for whatever field the expression was in. However, =MonthName(str(Month(today()))) worked for me. I am unsure of whether or not the MonthName method changed to require a string or if it is some issue with my program. Just figured I would post this in case anyone else was having the same issue.
For Previous Month i found universal way : =MonthName(Month(CDate(Today()))-1,False) for SEPTEMBER (Full Month Name) 'OR'
=MonthName(Month(CDate(Today()))-1,True) for SEP (Short Month Name)