SSIS: convert generated string into datetime: DT_WSTR to DT_DBDATE - date

I have this expression (DT_WSTR, 10)(year(getutcdate())-2)+"-01-01" that results in the string 2018-01-01.
NOw I want that string converted to a datetype but it complains that I cannot convert from DT_WSTR to DT_DBDATE (or any other datetype)
Curiously, it keeps complaining about WSTR if I try to use (DT_STR, 10,1252)(year(getutcdate())-2)+"-01-01"
How do I convert that generated string into a datetype DATE?
The ultimate goals is to get the 1st of january 2 years back at 12:00:00 AM
Since I am working on systems with different datesettings I prefer to avoid strings

Got it!
(DT_DATE)(DT_DBDATE)DATEADD("M",-MONTH(GETDATE())+1,DATEADD("D",-DAY(GETDATE())+1,DATEADD("YEAR",-2,GETUTCDATE())))

Related

Date Manipulation as a string in python 2.7

I am new to Python.I would like to know how I can manipulate a string that contains the date. For example, I want to transform today's date to the first day of the next year.
For example:
07/02/2018 --> 01/01/2019
How is that possible in Python 2.7?
You can use datetime package from python. Convert your string in to a date and do the manipulations. See more at here.
https://docs.python.org/2/library/datetime.html

DataStage Parsing Input String to Date Format

I have a string input format of i.e
'Thu, 30 Nov, 2017'
I need to transform this into a more Oracle database friendly Date type format of something like '11-30-2017' or '11/30/2017'. I started in the path of
Convert(' ','-',Convert(',','',DSLink.InputDate[5]))
which should return a string of: 30-Nov-2017
However I'm stuck on dynamically parsing the 'Nov' month part. Any clever ideas?
also I don't think this will work:
StringToDate(Convert(' ','-',Convert(',','',DSLink.InputDate[5])),"%dd-‌​%mm-%yyyy")
as the function is looking for a numeric type on the month field?

Error on converting String to Date

My date data looks like this: 20151112,20151116 .I want to convert it into Date "MM/DD/YYYY", then i used the Code:
=CDATE(MID(Fields!Date.Value,5,2)&"/"&(RIGHT(Fields!Date.Value,2)&"/"&LEFT(Fields!Date.Value,4)))
But there is an Error: Conversion from String 11/24/2015 to type Date is invalid. Can you please help me how to fix this Problem?
You are making your life harder than it needs to be by converting your string date into a potentially ambiguous localised date format (MM/dd/yyyy) and then trying to actually convert it to a date datatype. If you go about this the other way around - converting your data to a date data type and then formatting it - you will avoid a lot of headaches.
To do this, you need to first add in some forward slashes / to your string dates, retaining the yyyy/MM/dd:
=CDate(left("20160131",4) & "/" & mid("20160131",5,2) & "/" & right("20160131",2))
Now that you have a date data type that will always be properly handled by SSRS, you can format it however you require for being displayed in your application:
=format(CDate(left("20160131",4) & "/" & mid("20160131",5,2) & "/" & right("20160131",2)),"MM/dd/yyyy")

Create date from day, month, year as integers in KDB Q

I am trying to get a date from its integer components: I have day, month and year as variables (that can change, I don't want to hard code them), and I want to reunite them in a date variable.
For example, something like that;
myDay: 15
myMonth: 4
myYear: 2016
`date$(myYear,myMonth,myDay) --> should return 2016.4.15 (formatted as a date).
Any way to do that?
Thank you
q)d:3
q)m:8
q)y:2016
q)"D"$"." sv string (y;m;d)
2016.08.03
See cast vs tok - need to use different arguments depending on if what you're casting from is a string or not

converting a utc format date string to date object in Extjs

I have a date string in the format "2013-01-31T10:10:05.000Z". I want to convert this string to a Date object in extjs.
I have tried to use Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-dTH:i:s.uZ"). But it is returning undefined.
I also tried with new Date("2013-01-31T10:10:05.000Z"), but it is also returning undefined.
Note: I have tried in IE8 browser.
Could anyone please help me to convert the above date string to Date object?
Thanks a lot sra. Now I am getting the result as ...UTC+5:30... Is there any way to convert this in IST format?
Try Ext.Date.parse("2013-01-31T10:10:05.000Z","c");
The c is the format type for ISO 8601 formatted dates
See the Ext.Date API for more details on this or other available formats
That's because 'T' and 'Z' are special characters in the Date format: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date
You have to escape them like this: Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-d\\TH:i:s.u\\Z")