conversion from NSTimeInterval to days [closed] - swift

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a date1 and the current Date when the view did load.
Now I want to display how many days have passed since the day.
let timeInterval = date1.timeIntervalSince(date2)
Now I want to convert the timeInterval in days.
Anyone could help?

Rather than using TimeInterval you can get the number of days directly by using the Calendar class and DateComponents
let days = Calendar.current.dateComponents([.day], from: date1, to: date2)
print(days.day!)

Related

How to convert '02-3月 -21' to date 21-03-02 00:00:00 psql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to convert '02-3月 -21' to date 21-03-02 00:00:00? in postgresql or kettle
I think a simple replace can do the trick here. Just replace the Chinese character 月 with nothing and format it.
SELECT TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY');
// output: 2021-03-02 00:00:00+00
SELECT TO_CHAR(TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY'), 'YY-MM-DD HH24:MI:SS')
// output: 21-03-02 00:00:00

Postgres Select all Sundays in 2019 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
how would I go about selecting data from only Sundays in 2019 in Postgres?
I think Sundays are a 0 but I am unsure as to how to query it like that.
I am selecting from a preexisting table that contains timestamp strings like 2020-09-03 02:11:60, so basically I want to select all the timestamps that occurred in 2019 in my table usermetrics in the column timestamp.
You have two requests.
The first to find timestamps in 2019:
SELECT
*
FROM
usermetrics
WHERE
timestamp BETWEEN '01/01/2019'::date AND '01/01/2020'::date
The second to find those that occurred on Sundays:
SELECT
*
FROM
usermetrics
WHERE
timestamp BETWEEN '01/01/2019'::date AND '01/01/2020'::date
AND
extract(DOW FROM timestamp) = 0;
01/01/2020::date is used as 12/31/2019::date would miss timestamps that occurred after midnight.

Convert time format from 'MM/dd/yyyy HH:mm:ss' to 'MM-dd-yyyy' in hive [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How to convert time format from 06/23/2020 07:57:45 to 06-23-2020 in hive
Using split and concatenation:
with your_data as (
select '06/23/2020 07:57:45' as str
)
select concat_ws('-',splitted[0],splitted[1],splitted[2]) as Result
from
(
select split(str,'[/ ]') as splitted
from your_data
)s
Result:
06-23-2020
Using from_unixtime(unix_timestamp(string, format_from), format_to):
select from_unixtime(unix_timestamp(str,'MM/dd/yyyy HH:mm:ss'),'MM-dd-yyyy') as Result
from your_data
Result:
06-23-2020

Calulate number of days between datetimes [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to calculate the number of days between two datetimes in MATLAB.
startDate = datetime('12-Nov-2014 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss')
endDate = datetime('18-Feb-2016 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss')
Using diff I get the following result:
diff([startDate endDate])
ans =
11112:00:00
I am expecting a value of about 500 days not 11000.
If you can avoid to use datetime:
startDate = datenum('12-Nov-2014 00:00:00');
endDate = datenum('18-Feb-2016 00:00:00');
days = endDate-startDate
days =
463

Syntax error while comparing timestamps in PostgreSQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Error: "syntax error at or near interval"
Join in question:
... LEFT OUTER JOIN usersession e ON a.userID = e.userID AND e.lastAction >= now() interval '-4h' * 1"
lastAction was created as lastAction timestamp NULL DEFAULT NULL
The idea is, to return some nils if the session's timestamp is 4 hours older than the current time.
No idea what the deal is here, never had to compare timestamps before either.
If you want records for the last 4 hours you need:
now() - interval '4 hours'
instead of
now() interval '-4h' * 1