Netezza how read date time from character in the format of MON DD YYYY hh:mi am. I am getting an invalid date - date

In Netezza I have a field which contains characters which represents dates in the format of (I'm guessing) 'MON DD YYYY hh:miam'
select distinct nbr_cust
,as_of_date
,to_date(as_of_date,'Mon DD YYYY') as asOfDate
from MyNetezzaTable
Sample of the as_of_date
Jul 2 2018 4:30PM
Mar 6 2017 6:32PM
Feb 2 2016 12:58PM
Mar 31 2014 5:18PM
Jun 4 2018 6:55PM
I've tried to convert with to_date, and to_timestamp without any luck.
I keep getting an Invalid Date

Cause
The problem is the single digit hour. If the date string.
Resolving the problem
If it is not possible to ensure that the input strings always provide two digits for the hour value, you can use "FM" (fill mode) modifier in the template pattern. The “FM” prefix provides missing leading zeros. This SQL inserts the original string without error:
to_date(as_of_date,'Mon DD YYYY FMHH12:MIAM') as asOfDate

Related

Redshift to_date issue: Invalid date format; Specified day twice

I am trying to convert a string to date in Redshift.
select to_date('Fri Apr 03 00:00:07 2020','Dy Mon DD hh24:mi:ss YYYY')
I am getting an issue Invalid operation: Invalid date format: Specified day twice.
Is it not possible to mention both Day name and Day of month as a number in the same date string?
I am following this reference for date formats in Redshift
So you are specifying the date twice in your format string - day of week and day of month. Which is Redshift to use if they are in conflict? The reference you provided is general in nature, specifying both input and output format patterns (converting to a string you may want both date and day of week). If you just want to ignore the day of the week in the input string just use the format string 'XXX Mon DD hh24:mi:ss YYYY'.

Convert "Fri Apr 29 06:01:46 EDT 2016" to date format in HIVE?

I have a collected a bunch of tweets and loaded into Hive table. The time for each tweet is of the format "Fri Apr 29 06:01:46 EDT 2016". I would like to aggregate on only date i.e 04/29/2016.
Are there any functions that would help me get this format? Or should I do a substring to get year, month, date separately and collate them?
Any help is much appreciated, thanks in advance.
You need to use the built in date functions for this. Please find below the function usage for your case :
from_unixtime(unix_timestamp('Fri Apr 29 06:01:46 EDT 2016','EEE MMM dd hh:mm:ss z yyyy'),'MM/dd/yyyy')
The code snippet:
select from_unixtime(unix_timestamp('Fri Apr 29 06:01:46 EDT 2016','EEE MMM dd hh:mm:ss z yyyy'),'MM/dd/yyyy');
UPDATE
Refer this for the hive builtin date time UDFs.
And this for the timestamp formatting strings.

Datetime format change the number of returned rows in PostgreSQL

I really dont get this...
This first statement below returns the expected rows - ONLY rows which have a date which are BEFORE/SMALLER than...
select matchdate, price, size, issell from matchmsg
where matchdate <= '2015-01-17 00:00:00.000000+01' order by matchdate asc
The code below return rows with dates up to the 2015-01-21...!?
select matchdate, price, size, issell from matchmsg
where matchdate <= 'Sat Jan 17 2015 00:00:00 GMT+0100' order by matchdate asc
PS: I use PostgresSQL, NodeJS and NPM Moment...BUT the result is from the PostgreSQL tool pgAminIII...so - it has nothing to do with my own code...!
matchdate in the DB is a "datetime with time zone" like:
"2015-01-16 00:00:22.491956+01"
PostgreSQL does not understand dates of the format Sat Jan 17 2015 00:00:00 GMT+0100 but it's probably trying its best. Here are tables of the dates and time formats it does understand. A complete explanation can be found here.
You'll have to convert Sat Jan 17 2015 00:00:00 GMT+0100 to a format Postgres understands. It is very close to the HTTP date format.

How to convert string to date format in Tableau

I want to parse the following string
Wed Nov 18 20:22:45 +0000 2015
to date and time format in Tableau. Any idea how to use calculated fields? Tableau using the calculated field and DATEPARSE function?
Thanks
Try this:
Dateparse('EEE MMM dd hh:mm:ss Z yyyy', [YourString])
refer to http://userguide.icu-project.org/formatparse/datetime for a full list of parameters to specify your date.

Converting date into PostgreSQL format

I have a date time in format: Mon Jun 11 12:16:14 EDT 2013
I want it inserted in postgres as Date attribute, but postgres always inserts the current date time. I think it is the issue with the format. The normal date format in postgres is something like: 2012-06-13 04:24:45
How could I change Mon Jun 11 12:16:14 EDT 2013 format compatible to postgres?
Thank you!!!
You want the to_date or to_timestamp function.
You give it your string date, and a patten for how to parse the date. For your example it would be:
select to_timestamp('Mon Jun 11 12:16:14 EDT 2013', 'Dy Mon DD HH24:MI:SS ??? YYYY');
to_timestamp
------------------------
2013-06-11 12:16:14+01
I don't think you can't work with the timezone with these functions unfortunately (hence the ???)
You should also just be able to cast the string like:
'Mon Jun 11 12:16:14 EDT 2013'::timestamptz;