I currently have a sheet that looks at column "I" and displays in column "J" if the date is:
"Due in 8 days"
"Due in 7 days"
"Due in 6 days"
"Due in 5 days"
"Due in 4 days"
"Due in 3 days"
"Due in 2 days"
"Due Tomorrow"
"Due Yesterday"
"Due Today"
"Overdue within 7 days"
"Overdue within 14 Days"
"Overdue within 21 days"
"Overdue more than 30 days"
Formula:
=IF(I14=TODAY()+8, "Due in 8 days",
IF(I14=TODAY()+7, "Due in 7 days",
IF(I14=TODAY()+6, "Due in 6 days",
IF(I14=TODAY()+5, "Due in 5 days",
IF(I14=TODAY()+4, "Due in 4 days",
IF(I14=TODAY()+3, "Due in 3 days",
IF(I14=TODAY()+2, "Due in 2 days",
IF(I14=TODAY()+1, "Due Tomorrow",
IF(I14=TODAY()-1, "Due Yesterday",
IF(I14=TODAY(), "Due Today",
IF(I14>TODAY()-7, "Overdue within 7 days",
IF(I14>TODAY()-14, "Overdue 14-17 Days",
IF(I14>TODAY()-21, "Overdue 20-23 days", "Overdue 30-33 days")))))))))))))
THE QUESTION: What formula can I use to find:
"Due 4-7 days" and "Overdue 10-13 days"
Following both comments by #Matt
You'd need to change the formula.
and #Terry
Correct. But I can't find an example formula for something like "Overdue 10-13 days"
You should follow this pattern
=IF(AND(I14<TODAY()-14,I14>TODAY()-17), "Overdue 14-17 Days","rest_if_formula")
Do try figuring it out yourself (you can do it)
Related
Given day in week (let's say Monday), I need to find closest date (in future) to given date (for example 9-4-2016) which is this day in week (for these examples, it should be 11-4-2016).
This is a pure Ruby solution.
require 'date'
d = Date.strptime('9-4-2016', '%d-%m-%Y')
#=> #<Date: 2016-04-09 ((2457488j,0s,0n),+0s,2299161j)>
d + (1 - d.wday) % 7
#=> #<Date: 2016-04-11 ((2457490j,0s,0n),+0s,2299161j)>
1 is Monday's offset. d.wday #=> 6.
I have assumed that if the date falls on a Monday, the "closest" Monday is the same day. If it is to be the following Monday, use:
d + (d.wday == 1) ? 7 : (1 - d.wday) % 7
You can find this date in the nearest week of your date:
date = Date.parse('9-4-2016')
(date..date + 6).find {|d| d.strftime("%A") == "Monday"}
#=> Mon, 11 Apr 2016
I am using the NSDictionary to show the data in UITableview.
And Sections is now showing like -
My Log is - NSLog(#"%#",[self.base_dictionary allKeys]);
(
"2 days ago",
"2 weeks ago",
"4 weeks ago",
"5 days ago",
"1 week ago",
Today
)
Anyone can help how i can sort it properly -
("Today","2 days ago","5 days ago","1 week ago","2 weeks ago","4 weeks ago")
Change the key that is being used from a string to a numerical string containing the value of number of days since today, i.e. "000","014","028", "128", etc. This can then be used to sort the items, you'll need to ensure you have leading zeros otherwise the sort won't work correctly.
Then when you want to display the title for the section, use a method to calculate a string representation
So I have a booking system and a user can book a time slot.
The time slots are listed by day and time:
Wednesday - 10am to 2pm
Wednesday - 3pm to 9pm
Sunday - 3pm - 7pm
Tuesday 12pm - 4pm
What I need to happen is return some future dates based on the chosen time slot. So for example if I was to choose the Sunday slot above, another select field would be populated with dates.
The dates would be presented in a day and month format:
5th June
8th May
30th September
The dates would be Sundays only or what ever day was chosen in the time slot drop down list.
I would also need some way to limit how many dates were returned. So maybe every Sunday up to 6 months in the future.
I've taken a look in the API and can't seem to find anything for this.
Would appreciate your help.
Thanks for your time.
To get a list of upcoming days for a particular for the next 6 months, you can use something like this.
require 'date'
start_date = Date.today
end_date = 6.months.from_now
weekday = 0 # 0 for Sunday, 6 for Saturday
dates = (start_date..end_date).to_a.select { |day| day.wday == weekday }
After that, you can format the days as you like
dates.map { |date| date.strftime("#{date.day.ordinalize} %B %Y") }
=> # 12th October 2014
# 19th October 2014
# 26th October 2014
# ...
A slightly different approach than those solutions building ranges of dates, instead build a range of offsets and then build your dates.
start_date = Date.new(2014,10,15)
day_offsets = (0..180).find_all { |i| i % 7 == 0 }
dates = day_offsets.map { |d| (DateTime.now + d).to_date}
How about a method that takes an array argument of what days are selected and returns dates within a range and then format it to fit your needs.
def valid_date_range(days)
days.map! {|day| day.to_date.wday}
today = Date.today
till_date = Date.today + 1.month
valid_dates = (today..till_date).to_enum.select {|date| days.include?(date.wday)}
valid_dates.map {|date| date.to_formatted_s(:short) }
end
So if you needed Monday and Friday you'd call date_range(["Monday", "Friday"]) and it would return an array:
[" 7 Oct", "13 Oct", "14 Oct", "20 Oct", "21 Oct", "27 Oct", "28 Oct", " 3 Nov", " 4 Nov"]
Or, you may just want to play with till_date to get just the current months days like "Date.today.end_of_month" and get:
["10 Oct", "13 Oct", "17 Oct", "20 Oct", "24 Oct", "27 Oct", "31 Oct"]
I have an array that contains a series of hashes as listed below.
[{:pgs=>6, :oo=>"No", :ms_no=>"D3273", :auth=>"Johnson", :ms_recd=>"Mar 14", :ready_for_ce=>"Mar 15", :proj_back_from_ce=>"Apr 1", :final_ok=>"Jul 25", :pub_date=>"Aug 5", :notes=>" "},
{:pgs=>17, :oo=>"No", :ms_no=>"R4382", :auth=>"Jacobs", :ms_recd=>"Apr 12", :ready_for_ce=>"Apr 16", :proj_back_from_ce=>"May 17", :final_ok=>"Jul 10", :pub_date=>"June 10 ", :notes=>" "},
{:pgs=>15, :oo=>"No", :ms_no=>"L3291", :auth=>"Smith", :ms_recd=>"Mar 25", :ready_for_ce=>"Mar 26", :proj_back_from_ce=>"Apr 22", :final_ok=>"Jun 21", :pub_date=>"Aug 10 ", :notes=>"Au prompted for cx 4/30", nil=>" 5/15."}]
I need to take two take two date values within each hash: the one with the key :ms_recd and the one with the key :pub_date. I then will determine how many days spanned between the two date ranges (for example, 18 days).
Fortunately, I have the last part pretty much figured out. I just need to do
ms_recd1 = DateTime.parse('Apr 24')
pub_date1 = DateTime.parse('Aug 15')
(pub_date1 - ms_recd1).to_i
Which returns 115 (meaning 115 days). So let's say for three hashes, I'll pull out date ranges of 115, 162, and 94 days, and then I'd average it to 123.6 days.
My question is, how do I pull these date values out of this array to do this? I feel like this should be simple, but I can't figure out how it should work.
My question is, how do I pull these date values out of this array to do this?
You could write as to get those dates :
array.map{|h| h.values_at(:ms_recd,:pub_date)}
Full solution as #robertodecurnex commented :
array.map{|h| (DateTime.parse(h[:pub_date]) - DateTime.parse(h[:ms_recd])).to_i}
Im trying to show the number of weeks ago calculated from the week number
" x weeks ago "
this should just increment one week ago, two weeks ago, three weeks ago, 1 month ago, 2 months ago, 1 year ago.. etc
Im using method helper:
def weeks_ago_in_words(from_time, include_seconds = false)
to_time = Time.now
weeks_ago = ((to_time - from_time)/1.week).abs
[nil, "last week", "two weeks ago", "three weeks ago"][weeks_ago] ||
distance_of_time_in_words(from_time, to_time, include_seconds)
end
In view:
= weeks_ago_in_words(Time.local(2013) + week.to_i)
week = a week number like 1,10,28,52 etc
This does not give me correct resuls, is there a better way to calculate the "x weeks ago " based on the weeknumer?
If you are comparing two dates from the same year here is the code using cweek:
require 'date'
Time.now.to_date.cweek - Date.new(2013,1,1).cweek
If you are comparing two different years you'll have to add some conditional logic to determine your year multiplier as cweek returns the same value for Dec. 31, 2012 and Jan. 1, 2013.