last day of last month date expression in ssis - sql-server

I have to create a derived column to upload a date in OLEDB destination because my source file doesn't contain this date. The date i want to get through derived column is last day of last month. Does anyone know how to get it?

Try the following expression, just substract the current day from the current date using DATEADD Function.
DATEADD("d", -DAY(GETDATE()), GETDATE())
If you want to remove time you have two choices:
convert to string
LEFT((DT_STR,50,1252)DATEADD("d", -DAY(GETDATE()),GETDATE()),10)
convert to string then to date (it will generate time 12:00 AM)
(DT_DATE)LEFT((DT_STR,50,1252)DATEADD("d", -DAY(GETDATE()),GETDATE()),10)

The simplest way if you don't need time is :
(DT_DBDATE)(DATEADD("d",-DAY(GETDATE()),GETDATE()))

Related

Sort by date in Looker Studio (DataStudio)

so I am facing this issue with sorting the data, in the table, by the date. The thing is that I had to change format so that I can see the all together Day of Week, Date, Hour, Minute.
FORMAT_DATETIME("%a %d.%m.%y. %H:%M",MY DATE)
which caused that the sorting is now done alphabetically and the variable is treated as a text and not a date anymore.
enter image description here
Is there any way to include all information and be able to sort by date?
In the Looker Studio documentation (https://support.google.com/looker-studio/answer/9730334?hl=en) we find that FORMAT_DATETIME converts a date to formatted text.
Try to use PARSE_DATETIME (converts text to a date with time)
If you don't have the seconds part simulate them PARSE_DATETIME('%Y-%m-%d %H:%M:%S', CONCAT(DT_ATTRIBUTE, ':00'))

change the date in ssis package for XML file

I am working on SSIS in my XML file I have reading dates like 2013-08-02, 2013-08-4, 2013-08-05 but I have to change the data date to from last two days, What I mean is that the data date stamp should be changed to 2017-05-21,2017-05-22,2017-05-22.
what I was done is added a derived column in the SSIS package and changed the expression with GETDATE() in this case I am getting only today date, But I need to change data from last two days.
Can anyone help me?
Use the DATEADD function to add or subtract time from a date. In your Derived Column, use this in the Expression field:
DATEADD("d", -2, GETDATE())
Note that this does subtract the time value as well so if you need to convert to strictly date format (or time zone conversions) you will need additional code.

Day and month swapping only for single digits in SSIS

I have written an SSIS integration which fetches an employee and his expiry date. All the data is flowing correctly; however when a single digit day and month is present in expiry date, the destination column swaps the month and day (when the date has double unit for months or days its fine).
Example:
07/08/2016 to 2016-07-08 WRONG
15/03/2016 to 2016-03-15 CORRECT
since your date are in dd/MM/yyyy and you are in trying to convert it into datetime,so problem occurs.
I think this more safe,
declare #jk varchar(20)='07/08/2016'
select right(#jk,4)+'-'+substring(#jk,charindex('/',#jk)+1,2)+'-'+substring(#jk,1,2)

How to convert a date by using DAX functions?

I'm working on a PowerPivot project, and I need to convert a date to another format.
My SQL Server Analysis Cube provides me a Time dimension including a date attribute.
I want to convert it to a dd/mm/yyyy format to create a reference to another data source (Excel file).
I tried to convert it by using standard DAX date functions but it's not recognized as a date, it's seems it is due to the name of the day added as a prefix.
How can I transform it to the dd/mm/yyyy format ? How to extract the sub string after the comma ?
Thanks !
I used the following data to test my solution out.
You can use the SEARCH function to find the first instance of a string. So I can parse just the date portion out with the following formula:
=right([Datefield],(LEN([Datefield])-SEARCH(",",[Datefield])-1))
It gets the substring starting at the character after the comma through the end of the string.
The DATEVALUE function takes a string that represents a date and turns it into a date. I can combine that with my previous function:
=datevalue(right([Datefield],(LEN([Datefield])-SEARCH(",",[Datefield])-1)))
In the picture below, the first column is the original data. The second column is the function that parses out the substring for the date. The third column takes the datevalue of that date string in the second column. The fourth column is the all in one formula with both the substring and the datevalue.
If you will load the data from the database regularly, than I suggest you use Power Query to load data into PowerPivot Module.
Here is the sample code that can do the result for you.
Data look like this (Table2):
Date
Monday, January 12, 2014
Tuesday, January 13, 2014
Wednesday, January 14, 2014
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Split Column by Delimiter" = Table.SplitColumn(Source,"Date",Splitter.SplitTextByEachDelimiter({","}, null, false),{"Date.1", "Date.2"}),
#"Change to Date Format" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Date.1", type text}, {"Date.2", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Change to Date Format",{"Date.1"})
in
#"Removed Columns"
As #mmarie explained, the folowing formula works well (need some changes) :
=datevalue(right([Datefield];(LEN([Datefield])-SEARCH(",";[Datefield])-1)))

Setting Report date parameters

I have a report written in visual studio running on a SQL server 2005 DB.
I want it to automatically apply the day before's date
- start at 00:00:00 and end 23:59:59
From my pic the code I use is
=DateAdd(Dateinterval.day, -1, Now()) for the start date
and for end date I use
=Now()
These values get me a report for the last 24 hours but I want to get the report to run just for the 24 hours of the previous day. How would I do this?
I think you should be using Today() instead of Now().
Both will give today's date, but Today() will not include any time portion.
You should only use one date paramater being yesterday =DateAdd(DateInterval.Day, -1, Today()).
Then to use this your data should be truncated to the date only and filtered to equal this parameter getting yesterday only irrispective of the time.

Resources