Can't change Dateformat in Hive - hive

I can't change date format in Hive, please find the reference below.
AnalysisException: optigo_data.date_format() unknown---error for data format conversion
ex:2015-09-28 21:07:51 to 28-sep-2016
DATE_FORMAT(' 2015-09-28 ','%d-%b-%y')

Supported formats are Java SimpleDateFormat formats – https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

You might have to use regex call. try it out.
Below link might be helpful to you.
https://qnalist.com/questions/4658026/date-format-in-hive

Related

xslt 1.0 yyyy-MM-ddHH:mm:ss to YYYY-MM-DDTHH:mm:ss.sssZ

I'm using xslt 1.0 and trying to convert my date from yyyy-MM-ddHH:mm:ss to YYYY-MM-DDTHH:mm:ss.sssZ
Input sample
<StartDate>2014-07-2217:18:15</StartDate>
Required output format <startDate>2014-07-22T17:18:15.899+12:00</startDate> in NZST timezone
I tried with sample as in http://wiki.apache.org/cocoon/Tips/JavaInXslt without success as I'm getting the error that "The function 'sdf:new' was not defined". Also looked at EXSLT extensions for processing dates and times, but EXSLT don't have the function for timezone.
Kindly advice on how can I convert date from yyyy-MM-ddHH:mm:ss to YYYY-MM-DDTHH:mm:ss.sssZ other than using the concat "+12:00" to the end of startDate value?
Thanks in advance!
how can I convert date from yyyy-MM-ddHH:mm:ss to
YYYY-MM-DDTHH:mm:ss.sssZ other than using the concat "+12:00" to the
end of startDate value?
There is no other way*. XSLT 1.0 has no concept of dates; your data is a meaningless text string, and needs to be manipulated as such.
--
(*) Unless you create your own way by extending your processor capabilities with a user-defined function, as you have tried. But that 's a different question - and IMHO a solution using string functions is trivial and satisfactory.

Change sql Get date to format ccmmdd?

I am trying to find out how to change my get date into the format of ccmmdd?
So far the closest iv come is ccyymmdd with:
CONVERT(VARCHAR(8),GETDATE(),112)
This produces 20140505, What i'm looking for is 140505.
Is there a link i can follow to see the different sql date formats, or would this be best done through string manipulation?
Try this:
CONVERT(VARCHAR(8),GETDATE(),12)
The list of available formats can be found here:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
This also works.
RIGHT(CONVERT(VARCHAR(10),GETDATE(),112),6)

Pig - How to cast datetime to chararray

I'm using CurrentTime(), which is a datetime data type. However, I need it as a chararray. I have the following:
A = LOAD ...
B = FOREACH A GENERATE CurrentTime() AS todaysDate;
I've tried various approaches, such as the following:
B = FOREACH A GENERATE (chararray)CurrentTime() AS todaysDate;
However, I always get ERROR 1052: Cannot cast datetime to chararray.
Anyone know how I can do this? By the way, I'm very new to pig. Thanks in advance!
I had a similar issue and I didn't want to use a custom UDF as described in the other answer. I am pretty new with Pig but it seems a pretty basic operation to justify the need of an UDF. This command works great for me:
B = FOREACH A GENERATE ToString(yourdatetimeobject, 'yyyy-MM-dd\'T\'HH:mm:ssz') AS yourfieldname;
You can select the format you want by looking at the SimpleDateFormat javadoc
You need to create a custom UDF which does the conversion
(e.g: see CurrentTime() implementation). Alternatively you may check out my answer on a similar topic for workarounds.
If you are on AWS, then use their DATE_TIME UDF.

Can anyone translate this dateformat?

I’m having a problem with date formats.
I need to convert the following string into af date object: 2011-09-19T12:23:51Z
And then convert the date object back to a string with this format: 19. september 2011
I can’t figure out what the “T” and “Z” is all about though?
Can anyone help me?
Kind regards
Jesper
The "T" is to separate the date from the time.
The "Z" shows that this is in UTC.
This is a standard (extended) ISO-8601 format date/time string - it should be easy to parse with whatever libraries iOS provides.

Format date like M/D/Y

I got a date of the type SYDATUM and wondering how to format it in a format like m/d/y.
I've found some snippets on the web, but they were not really helpful.
-thanks yor your help.
You should be more specific - what exactly do you want to do with the date (use type D internally, it's shorter and does the same thing).
Do you want to WRITE it to a list screen? Use the formatting options described in the documentation and online help:
WRITE l_my_date MM/DD/YYYY.
Do you want to convert it to a text variable? Very similar:
WRITE l_my_date TO l_my_text MM/DD/YYYY.
To set the date format in a SAPscript form, see the SET DATE MASK command.
To print the formatted date in a SmartForm, use the WRITE command and a temporary variable (yes, ugly, I know...)
Most controls (ALV Grid for example) should take care of the format automatically.
However - be careful when hard-coding the format into your application. Usually you don't have to do this because the system automatically uses the format specified in the user master data. This ensures that every user will see the date formatted according to their locale settings.
Normally it's better to export the date into the plant level country specific date format:
if w_country is initial.
select single LAND1
from T001W
into w_country
where WERKS eq w_the_plant.
endif.
SET COUNTRY w_country.
write w_the_date to w_export.
for example 03/04/2002 could be different date in different country.
You can try the keyword TRANSLATE. Alternatively suggest you could have a look at this link