I have a string that I need to insert into a table as a timestamp.
'Thu Jul 02 13:36:17 UTC 2020'
Without UTC the following conversion works
SELECT to_timestamp('Thu Jul 02 13:36:17 2020', 'Dy Mon dd HH24:MI:SS yyyy');
How can I convert the timestamp with the UTC portion?
Any help would be greatly appreciated!
Database Type: PostgreSQL
Table Data Type: timestamp (this can change if needed)
If it's always going to be UTC, then you can use:
> select to_timestamp(
'Thu Jul 02 13:36:17 UTC 2020',
'Dy Mon DD HH24:MI:SS UTC YYYY'
);
Related
Date startDate = new Date(Long.valueOf(""05/07/2018")getValue().toString());
get last day of selected month is required
private Date lastDayOfMonth(Date month) {
Date lastDay = (Date) month.clone();
CalendarUtil.addMonthsToDate(lastDay, 1);
CalendarUtil.setToFirstDayOfMonth(lastDay);
CalendarUtil.addDaysToDate(lastDay, -1);
GWT.log("lastDay :: "+lastDay);
return lastDay;
}
I get lastDay :: Tue Jul 31 00:00:00 GMT+530 2018
But i get 30th instead of 31st
First, your code does not work
Date startDate = new Date(Long.valueOf(""05/07/2018")getValue().toString());
Second, your method private Date lastDayOfMonth(Date month) looks fine, I have a test and got result Tue Jul 31 00:00:00
I dont understand your problem "Tue Jul 31 00:00:00 GMT+530 2018 But i get 30th instead of 31st". How can you get 30th from Tue Jul 31 00:00:00 GMT+530?
How can I transform this date format :
Wed Jan 04 2017 18:19:13 GMT+0100 (CET)
To ISO date format?
If I do:
let date = new Date(value);
On Browser and Android works fine but when I use on IOS it returns a invalid date error
Thanks
Using Heroku, I am trying to compare a saved times (open and close) of a place to the current time to determine what to output.
Code:
def get_place_search_display(open_time, close_time)
open_time_formatted = open_time.strftime('%l:%M %p') if !open_time.nil?
close_time_formatted = close_time.strftime('%l:%M %p') if !close_time.nil?
current_time = Time.current #.strftime('%l:%M %p')
if open_time.nil? || close_time.nil?
"Closed today"
elsif current_time < open_time
"Opens at #{open_time} until #{close_time}"
elsif current_time >= open_time && current_time <= close_time
"Open #{open_time} - #{close_time}"
elsif current_time > close_time
"Closed at #{close_time} today"
else
"Open until #{close_time} today"
end
end
Example returned values:
Open time: 7:00 AM
Close time: 8:45 PM, 2000-01-01 20:45:00 UTC
Current time: 6:35 PM, 2014-09-07 18:35:36 -0700
Returns: "Closed at 2000-01-01 20:45:00 UTC today"
Any ideas what the comparison isn't working using this logic?
Looking at the term "today" in your output string, and also the '%l:%M %p' in your time formatting method, I assume you are trying to compare Time objects without Date info
However in Ruby, Time object always comes with date. But you can achieve that by converting them into the same day before comparing them.
a = Time.current
=> Mon, 08 Sep 2014 02:30:44 UTC +00:00
b = Time.current.months_ago(1)
=> Fri, 08 Aug 2014 02:30:59 UTC +00:00
a > b
=> true
a2 = a.change(day:1, month:1, year:2000)
=> Sat, 01 Jan 2000 02:30:44 UTC +00:00
b2 = b.change(day:1, month:1, year:2000)
=> Sat, 01 Jan 2000 02:30:59 UTC +00:00
a2 > b2
=> false
Hope it helps.
In Go I'm trying to use the time.Parse() function from the time package to convert a string timestamp into a Time object. I know Go has an uncommon way of representing the time format your timestamps are in by providing it with an example of how their reference time (Mon Jan 2 15:04:05 -0700 MST 2006) would be displayed in your format. I'm still having issues with errors however. Here is an example of one of my timestamps:
Tue Nov 27 09:09:29 UTC 2012
Here is what the call I'm making looks like:
t, err := time.Parse("Mon Jan 02 22:04:05 UTC 2006", "Tue Nov 27 09:09:29 UTC 2012")
So basically what I've done here is try and match the formatting for day name/month name/day number, the hour/minute/second format, the string literal "UTC" and the year format. Note that I've increased the hours field of the Go reference format by 7 (from 15 to 22) to account for the fact that their timestamp is in a negative 7 timezone and all my timestamps are in a UTC timezone.
The error I get is:
parsing time "Tue Nov 27 09:09:29 UTC 2012" as "Mon Jan 02 22:04:05 UTC 2006": cannot parse ":09:29 UTC 2012" as "2"
What am I doing wrong here? Am I misinterpreting how to use time.Parse() or is my use case not supported for some reason?
Your format string should be:
Mon Jan 02 15:04:05 MST 2006
playground
That is, use MST for the timezone and 15 for the hour, as documented in your linked Parse function.
In this case, you can use time.UnixDate:
package main
import (
"fmt"
"time"
)
func main() {
t, e := time.Parse(time.UnixDate, "Tue Nov 27 09:09:29 UTC 2012")
if e != nil {
panic(e)
}
fmt.Println(t)
}
https://golang.org/pkg/time#UnixDate
Trying to do a proof of concept of loading sample tick data into mongo db and the tick archive data is generally in utc and epoch and need to load it as is and output as utc only not local datetimes.
How to insert utc datetime and epoch in mongodb without being cast into utc again and retrieve the
same as utc only.
db.equity_ticks.insert(
{
"SNAPSHOT_DTTM" : Date("2013-07-09 19:00:00.000000"),
"CLOSE_DATE" : Date(15895) ,
"PREV_DAY_CLOSE_DATE" : Date(15895)
}
instead it inserted the local CST and output as CST too !
db.equity_ticks.find().pretty()
{
"_id" : ObjectId("52040942e5171b792b258ae8"),
"SNAPSHOT_DTTM" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)",
"CLOSE_DATE" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)",
"PREV_DAY_CLOSE_DATE" : "Thu Aug 08 2013 16:10:26 GMT-0500 (CDT)"
}
any help is appreciated.