Convert date to other format other than YYYY-MM-DD - teradata

I need to convert input date coming in format YYYY-MM-DD. First I convert it into char by following:
TO_CHAR(<date_column>,'YY/MM/DD')
then try to convert it into date for this format:
to_date((TO_CHAR(<date_column>,'YY/MM/DD')),'YY/MM/DD')
As to_date always converts to default date type of YYYY-MM-DD. What other way can I use to convert this into other format. I am using Informatica Powercenter, so I can not find other function other than TO_DATE.

I think we are ignoring basics - to_date() converts to a date format. Now it can be displayed in dd/mm/yyyy depending on setup in your DB client or if you are dumping in a file probably YYYY-MM-DD. And on a date filed you cfan use TO_CHAR o convert it to any format.
So, if your input is a string and is in 'YY/MM/DD' then use TO_CHAR(TO_DATE(imp_yymmdd,'YY/MM/DD'),'DD/MM/YYYY') - output will be a string of your desired format i.e. DD/MM/YYYY.
If your input is a date then use TO_CHAR(imp_date,'DD/MM/YYYY') - output will be a string of your desired format.

Date datatype has no format. You can format a string representing a date.
Assuming your input is date, just use TO_CHAR(yourdate, 'desiredformat').
If your input is a string, you first need to convert it to date then back to string again, with the desired format applied. So:
TO_CHAR(TO_DATE(yourstring, "format-it-comes-in"), "desired-format")
Which in your case would be:
TO_CHAR(TO_DATE(yourstring, "YYYY-MM-DD"), "YY/MM/DD")

Related

How to change UK date format in LogicApp

Im trying to convert a U.K. input date (dd-MM-yyyy) to format (yyyy-MM-dd)
I tried
"#formatDateTime('15-03-2019','yyyy-MM-dd')" ==> Error
but got error:
'In function 'convertTimeZone', the value provided
for date time string '15-03-2019' was not valid. The datetime
string must match ISO 8601 format.'
How do I go about converting this input date? The input format is (dd-MM-yyyy) and cannot be changed.
I can easily convert from (MM-dd-yyyy) as shown below, but im not able to convert from (dd-MM-yyyy)
"#formatDateTime('03-15-2019','yyyy-MM-dd')" ==> OK
Date and time functions provided by azure logic app cannot recognize the timestamp in dd-MM-yyyy format.
After my research, there is no existing function that can directly solve this problem, but you can use substring and concat to deal with this problem.
The workflow of the logic app looks like this:
The expression of the formatDataTime:
formatDateTime(concat(substring(<your-date-string>,6,4),'-',substring(<your-date-string>,3,2),'-',substring(<your-date-string>,0,2)),'yyyy-MM-dd')

In R, take a date string and convert it to datetime format (using lubridate)

In R I am trying to take a date string and convert it to date time format using lubridate but anm getting an error that:
All formats failed to parse. No formats found.
Using this code:
lubridate::as_date("1/2/34")
Shouldn't this just return a formated date time?
as.Date or as_Date needs format. By default, it can parse if the format is %Y-%m-%d. Here, it is not the case. So
lubridate::as_date("1/2/34", format ="%d/%m/%y")
Or more compactly
lubridate::dmy("1/2/34")
Based on the string, it is not clear whether it is day/month/year or month/day/year. Also, for 2-digit year, there is an issue with prefix i.e. it can be either "19" or "20". Here, it would parse at "2034"

How can I convert datetime to date format in SQLite?

I want to show a date in DD-MM-YYYY format in a datagrid. By default, SQLite stores the data in date-time format. So how can I convert date-time format to date format in flex by using SQLite?
You can use strftime, from Date And Time Functions.
Example:
SELECT strftime('%d-%m-%Y', 'now')
output:
10-06-2010
Look up Java until Date. It has methods to convert and is supported in SQLite. However it is mostly deprecated and replaced with Calender.

How to covert mm/dd/yyyy to dd/mm/yyyy

I have a textbox in which date is in format mm/dd/yyyy. I want to convert it from mm/dd/yyyy to dd/mm/yyyy in asp.net with vb to a DateTime variable.
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture).ToString("dd'/'MM'/'yyyy")
Update: Given that you want to have a DateTime in the end, you can just parse the original format:
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture)
The date formats are of use only when presenting the date as a string (internally the date does not have a format; it's just a number). If you want to store it in a DateTime all you need to bother about is to interpret the input correctly.
If you are dealing with a DateTime object you convert can like this:
yourDateTime.ToString("dd/MM/yyyy"))

How can I convert a datetime to dd-mmm-yyyy Date format?

I'm using Webdatechooser<<Infragistics control>> for a column which takes the datetime.
I need to convert the value entered (through the Webdatechooser) to dd-mmm-format.
Can I have snippets for that?
The value is a DateTime object so you can use the ToString function of that object to generate the desired output.
((DateTime)WebDateChooser1.Value).ToString("dd-MMM-yyyy");
Should do it.

Resources