Converting date into PostgreSQL format - postgresql

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;

Related

Netezza how read date time from character in the format of MON DD YYYY hh:mi am. I am getting an invalid 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

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.

MongoDB/mongoose some dates as EDT and others as EST

When getting some records, I'm seeing that some dates are showing as GMT-0400 (EDT) and others are GMT-0500 (EST).
Dates are being added in mongoose simply by using Date.now in the schema.
Any ideas what could cause the offsets to be different?
Edit: Here's an example:
Stored as: ISODate("2015-10-30T15:36:47.287Z") Returned as: Fri Oct 30 2015 11:36:47 GMT-0400 (EDT) using find() with Mongoose
Stored as: ISODate("2015-11-07T14:44:47.956Z") Returned as: Sat Nov 07 2015 09:44:47 GMT-0500 (EST) using find() with Mongoose
It's just the default string representation of the underlying UTC timestamp, showing the timestamp in the local time zone that was in effect at the time.
In 2015, daylight saving time ended at 2:00 AM on Nov 1, so that's why the first one is shown in EDT and the second one is shown in EST.
Any queries you do are always performed using UTC time.

MongoDB java-driver insert date

I'm using MongoDB 2.2 with java-driver 2.10.1
I'm inserting a date field into a document from a java.util.Date instance. My instance has the following value:
Wed Oct 10 00:00:00 CEST 2012
but once in mongo, I have this value:
ISODate("2012-10-09T22:00:00Z")
My insertion code:
BasicDBObject doc = new BasicDBObject("key", event.getKey())
.append("title", event.getTitle())
.append("description", event.getDescription())
.append("date", event.getDate());
db.getCollection("events").insert(doc);
You can have a look to the date instance referenced from my event object on this debug screenshot:
Is there something to do with the timezone ? Or a bug from the driver ?
Dates in MongoDB are always stored as UTC datetimes, so what you're seeing is correct.
The CEST time zone is two hours ahead of UTC (GMT) so your time's correct UTC representation is two hours earlier than your CEST time, which is exactly what you're seeing.