I have two UIDatePickers. startDatePicker is to choose a start date and endDatePicker is to choose an end date. It should be something like
START: 2015/06/25 11:00
END: 2015/07/06 13:00
->Time Interval: 12 days 2 hours = 1044000 seconds
And the 1044000 seconds is what I want to get here. Just I am not sure how.
I am guessing maybe I can use
startDatePicker.date.timeIntervalSinceDate(endDatePicker.date)
to get the value? If so, what is the necessary settings for the two UIDatePickers?
Or maybe there are other ways to do that? Thanks in advance.
Related
I know it's basic but I'm new to this. I just want to know how can I calculate the days duration of the two dates?
For example, I have my start date and time 11/22/2021 15:20:43 and end date and time 11/23/2021 14:51:29 I want to calculate the total days from start to end date and time.
Also, If start date time column is BLANK, return to count of days including date today.
Thank you
All you need to do is use the following formula: '=(C2-A2)'. This will give you the elapsed time between the two cells and display it as hours. You can take this calculation further by adding dates too. This is useful if you have work shifts that go more than 24 hours or that include two days within a single shift.
Assuming start dates in column A and end dates in column B, you can try
={"Duration in Days"; Arrayformula(if(len(A2:A) * len(B2:B), datedif(A2:A, B2:B, "d"),))}
Change ranges to suit and see if that works?
EXAMPLE
REFERENCES:
DATEDIF
there is a DAYS formula exactly for that purpose:
update:
=INDEX(IFERROR(1/(1/DAYS(
REGEXREPLACE(TO_TEXT(B1:B), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3"),
REGEXREPLACE(TO_TEXT(A1:A), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3")))))
demo sheet
There's the subtract() method but the documentation says it's not aware of daylight savings which makes it pretty much useless in this case, or in any other case except where the programmer doesn't know how many milliseconds there are in 24 hours.
I'm thinking of two ways:
get the day of the month, and then subtract N from it and if it's less than 1 then subtract the month and the year if appropriate and set the day for the last day of whichever month it turns out to be
OR
subtract N days from the noon of the current day and then get start of the day for the resulting day
Is there some easier/better way to do this?
You should probably try to convert both DateTimes to UTC (standardize), then call difference(). That converts it to a nice, easy Duration, which you can convert as necessary to hours, days, months, or whatever else.
DateTime one = somedatetime.toUtc();
DateTime two = someotherdatetime.toUtc();
Duration diff = one.difference(two);
//Then just convert...
return diff.inDays;
I have set datePickerMode: .time and gave max and min hour. But I want to disable minutes selection but didn't find any solution. I can give minutesInterval but I just want to show or choose only 00 for minutes. User must select only hour.
Thanks for your help
What if you set the minuteInterval property of the date picker to 60?
If that doesn't work, and the only thing you're using the date picker to collect is hours, why not create a regular UIPickerView with hour values from 12 AM to 11 PM? (Or 0 AM to 23 PM, if you're using 24 hour time.)
I have a start_at, a decimal quantity and an interval which is one of day | week | month | year.
start_at = Time.parse('2016-01-01 00:00:00 UTC') # leap year
quantity = BigDecimal.new('1.998') # changed from 2.998, should end on 2/29/16 sometime
interval = 'month' # could be any of day|week|month|year
With whole numbers, I've used duration i.e. 1.month, and I looked at Date#advance, though it only recognizes integer values.
It would seem simple but I cannot find anything in the standard libraries or in ActiveSupport.
References:
SO answer potentially used for input to Date#advance?
SO explanation of duration
Question
How can I establish the end_at date from a decimal?
Why? What purpose?
Proration to the second for a given amount and given interval.
Expectations
I'm looking for an end_at to the second as accurate as possible with respect to advancing the next interval(s) by the decimal quantity. Given interval = 'month', for the fractional part, when you pass the start of the month, means you are in that month and using it's duration. For example, January 2016 is 31 days, while February (leap) is 29 days (only in the leap year).
I'd say your best option is to use Ruby's date methods to advance time based on the whole number of the decimal, then calculate how many seconds your fraction is of your current interval.
So for 1.998 months, advance time 1 month. Find the current month you are in and get the .998 of the seconds in that month (i.e. for July, 31x24x60x60x.998) and then advance time that many seconds.
What does advancing time a fractional month mean?
Lets say we have the following date 2015-01-01 00:00:00 UTC. It is easy to advance exactly 1 whole month, we simply increment the number that represents months: 2015-02-01 00:00:00 UTC. Alternatively, we could view this as adding 31 days, which we know is the number of days in January.
But what if we want to advance 0.5 months from 2015-01-01 00:00:00 UTC?
We can't just increment like we did when advancing a whole month. Since we know January has 31 days, perhaps we could just advance 15.5 days: 2015-01-16 12:00:00 UTC. That sort of works.
How about 1.5 months from 2015-01-01 00:00:00 UTC? If we combine our previous approaches, we'd first increment, getting us to 0.5 left to advance and 2015-02-01 00:00:00 UTC. Then we'd take half of 28 and get to 2015-02-15 00:00:00 UTC.
But wait, what if instead we took the total number of days between the two months and then took 3/4 of that? Like 2(month) * (3/4), which would simplify to (3(month)) / 2, or 1.5(month). Lets try it.
(28 days + 31 days) * 0.75 = 44.25 days
Now adding that to 2015-01-01 00:00:00 UTC we get 2015-02-14 06:00:00 UTC. That's three-quarters of a day off from our other answer.
The problem here is that the length of a month varies. So fractional months are not consistently definable.
Imagine you have two oranges. One contains a little bit more juice than the other (perhaps 31ml and 29ml of juice). Your recipe calls for the juice of 1.5 oranges. Depending on which one you decide to cut in half, you could have either 44.5 ml or 45.5 ml. But if your recipe calls for 40 ml of orange juice, you can pretty consistently measure that. Much like you can consistently (kind of) increment a date by 40 days.
Time is really tricky. We have leap seconds, leap years, inconsistent units (months), timezones, daylight saving time, etc... to take into account. Depending on your use case, you could attempt to approximate fractional months, but I'd highly recommend trying to avoid the need for dealing with fractional months.
I wonder if there is a way to custom a datepicker's time range?
How can I remove minute column and leave only 9 and 5 in hour column? is that possible?
Maybe you should considere to use this cocoapod:
https://www.cocoacontrols.com/controls/dvdatepickertableviewcell
or this webpage:
http://blog.deeplink.me/post/81386967477/how-to-easily-customize-uidatepicker-for-ios
and try to custom it as you want.
For UIDatepicker it is not possible to remove the minutes column or only to show 9 and 5 hour in hour column.
UIDatePickerModeDateAndTime:
The date picker displays dates (as unified day of the week, month, and day of the month values) plus hours, minutes, and (optionally) an AM/PM designation. The exact order and format of these items depends on the locale set. An example of this mode is [ Wed Nov 15 | 6 | 53 | PM ].
You need to use custom datepicker for that,you may consider to look at this link for custom picker https://github.com/mwermuth/MWDatePicker
for MWDatePicker first date were invisible but changing the font color like this [datePicker setFontColor:[UIColor blueColor]]; in viewdidLoad in MWViewController.m make them visible.And then modifying the method fillWithCalendar in MWDatePicker.m like this
- (void)fillWithCalendar{
minutes = #[#""];
hours = #[#"05",#"09"];
////others coding
}
i think would give you desired output.