Is there way to convert Friday, August 31, 2018 12:12 PM into this format 2018-08-31 12:12 PM in sql? - sql

I am trying to find a difference between two dates both in different formats. Is there way to convert Friday, August 31, 2018 12:12 PM into this format 2018-08-31 12:12 PM in sql? and how can I then find the difference?
the results should be in hh:mm:ss format, using metabase to run queries.

Related

PostgresSql - Filtering data between dates which in format like Mon Jun 20 2022 10:04:01 GMT+0530 (India Standard Time)

PostgresSql - Filtering data between dates which in format like Mon Jun 20 2022 10:04:01 GMT+0530 (India Standard Time). I want to filter data between 2 dates
i.stack.imgur.com/Hu91J.jpg

"Mon Mar 14 00:04:26 +0000 2016" to "yyyy-mm-dd" format in Hive?

I have the following "Mon Mar 14 00:04:26 +0000 2016" and I want to convert it into "yyyy-mm-dd" format in Hive. Can someone help me with this?
Try this.
SELECT from_unixtime( unix_timestamp('Mon Mar 14 00:04:26 +0000 2016',
'EEE MMM d H:mm:ss +0000 yyyy'), 'yyyy-MM-dd');
2016-03-14

How to convert '10-OCT-17 07.57.14.253290000 AM' text into date format '2017-10-10 07:57:14'?

I want to convert 10-OCT-17 07.57.14.253290000 AM date format into 2017-10-10 07:57:14
and
10-OCT-17 12.57.14.253290000 PM date format into 2017-10-10 12:57:14
and
10-OCT-17 07.57.14.253290000 PM date format into 2017-10-10 19:57:14
I want AM and PM should come into consideration .
cast(to_timestamp(pub_ts ,'dd-mon-yy HH.MI.SS') as timestamp without time zone)
Where pub_ts is a text. I have used this 15 days back through this would work.
It converts
10-OCT-17 12.57.14.253290000 PM date format into 2017-10-10 00:57:14
I assume you just need a right mask? EG:
postgres=# with e(v) as (values('10-OCT-17 12.57.14.253290000 PM'),('10-OCT-17 12.57.14.253290000 AM'))
select v,to_timestamp(v,'DD-MON-YY HH12.MI.SS.US000 AM')::timestamp(0) from e;
v | to_timestamp
---------------------------------+---------------------
10-OCT-17 12.57.14.253290000 PM | 2017-10-10 12:57:14
10-OCT-17 12.57.14.253290000 AM | 2017-10-10 00:57:14
(2 rows)

Compare NSDates across timezones

I'd like to compare and filter NSDates to determine whether there are any for today regarding the users current timezone.
Let's say I've a user located in Los Angeles (UTC-8 hours) and the following dates:
TargetDate
UTC: 2 pm (14:00) - 12. Feb 2017
LocalTime: 10 pm (22:00) - 12. Feb 2017
Now
UTC: 10 pm (22:00) - 11. Feb 2017 // Change of date!
LocalTime: 6 pm (06:00) - 12. Feb 2017
Today
UTC: 00 am (00:00) - 11. Feb 2017 // Begin of today
Tomorrow
UTC: 00 am (00:00) - 12. Feb 2017
In the next step I'd like to compare the TargetDate, Today and Tomorrow to determine, if the TargetDate is between Today and Tomorrow. This is where the problem is. When I compare the dates I receive an answer that it is of course not between these dates.
+ (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate
{
if ([date compare:beginDate] == NSOrderedAscending)
return NO;
if ([date compare:endDate] == NSOrderedDescending)
return NO;
return YES;
}
What I can do, is to convert the UTC date, TargetDate, to the local timezone but I'm very confused whether this is the best solution. In this post it's mentioned that you shouldn't do this because it confuses the whole problem.
Does anyone has an idea, how to solve this problem?
The problem you are having is actually here:
Today
UTC: 00 am (00:00) - 11. Feb 2017 // Begin of today
Tomorrow
UTC: 00 am (00:00) - 12. Feb 2017
You're deciding that the "day" is the UTC day. Instead, you need to determine the day in the target time zone.
Today
LocalTime: 00 am (00:00) - 11. Feb 2017 // Begin of today
UTC: 08 am (08:00) - 11. Feb 2017 // Equivalent UTC
Tomorrow
LocalTime: 00 am (00:00) - 12. Feb 2017 // Begin of tomorrow
UTC: 08 am (08:00) - 12. Feb 2017 // Equivalent UTC
Do keep in mind a few other things:
Compare with half-open intervals: StartOfToday <= SomePointToday < StartOfTomorrow (inclusive start, exclusive end).
America/Los_Angeles is not always UTC-8. It switches to UTC-7 during daylight saving time.
Not every day starts at midnight. For example, America/Sao_Paulo on 2016-10-16 started at 01:00. The 00:00 hour was skipped for DST.
If you just care about some point on that day, rather than the entire day, compare at 12:00 noon, rather than at 00:00 midnight. It avoids the DST problem.

Time zone for Force.com API fiscal date literals?

I have a question about fiscal date literals in the Force.com API (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm):
For which time zone are date ranges calculated?
For example, suppose we execute the query:
SELECT Id FROM Opportunity WHERE CloseDate = THIS_FISCAL_QUARTER
where, according to our company's fiscal settings, THIS_FISCAL_QUARTER runs from Jan 1 to Mar 31.
Does the range for THIS_FISCAL_QUARTER use...
the user's time zone? For example, if the user's time zone is GMT-8, THIS_FISCAL_QUARTER = Jan 1 00:00 GMT-8 to Mar 31 23:59 GMT-8 (or Jan 1 08:00 UTC to Mar 31 07:59 UTC)
the company's default time zone (according to the company profile)? For example, if the company's default time zone is GMT-8, THIS_FISCAL_QUARTER = Jan 1 00:00 GMT-8 to Mar 31 23:59 GMT-8 (or Jan 1 08:00 UTC to Mar 31 07:59 UTC)
UTC? THIS_FISCAL_QUARTER = Jan 1 00:00 UTC to Mar 31 23:59 UTC
something else?
From my experience (fun with reports, not queries) the note from all the way on bottom is valid also for time literals. So it uses running user's timezone setting.
These values are offset by your timezone. For example, in the Pacific timezone, the earliest valid date is 1699-12-31T16:00:00, or 4:00 PM on December 31, 1699.
Maybe you can simply create a test record with datetime field just slightly outside the fiscal quarter and query for it "WHERE mydatetimefield__c > THIS_FISCAL_QUARTER"?
See also http://forums.sforce.com/t5/General-Development/SOQL-Date-literal-TODAY-is-evaluated-incorrectly/m-p/43607