Finding week and Month from Number
Moderators: chulett, rschirm, roy
Finding week and Month from Number
Hello,
I have requirement where I need to find the difference between 2 days and check if it Week1, Week2, Week3 , Week4 or month1 or Month2 Etc.
I have calculated the difference by applying below mentioned function i..e.
Number =DaysSinceFromDate(D1,'2010-01-01')
My output should be as folows:-
Number Output should be
6 Week1
12 Week2
24 Week2
33 Month1 and so one.
We may have max 1 Year data i.e. 365 days. so max. the output value can be Month 12.
We have to make sure that leap year is also considered.
Please let me know is there any functions or I need to write a If else statement.
Regards
Neeraj
Please let me know
I have requirement where I need to find the difference between 2 days and check if it Week1, Week2, Week3 , Week4 or month1 or Month2 Etc.
I have calculated the difference by applying below mentioned function i..e.
Number =DaysSinceFromDate(D1,'2010-01-01')
My output should be as folows:-
Number Output should be
6 Week1
12 Week2
24 Week2
33 Month1 and so one.
We may have max 1 Year data i.e. 365 days. so max. the output value can be Month 12.
We have to make sure that leap year is also considered.
Please let me know is there any functions or I need to write a If else statement.
Regards
Neeraj
Please let me know
-
- Participant
- Posts: 437
- Joined: Fri Oct 15, 2004 6:13 am
- Location: Pune, India
Finally, here is the sample:
Code: Select all
if NoofDays<=31 then Ceil(NoofDays/7):"Week"
else(if NoofDays>=32 and NoofDays<=60 then 2:"Month" else(if NoofDays>=61 and NoofDays<=90 then 3:"Month" else...........
pandeeswaran
It's not clear enough yet. I think if you are clear on the business rules then you can state a more clear requirement.
Do you need to determine the week number, the month number, both week and month numbers, or does it depend on something?
It looks like you have made assumptions that the number only falls into week 5 if the number is in range 29-31. And also that number only falls into month 2 starting with number = 32. What about leap years?
Calendars don't always work like that. Week and month definitions can vary based on business rules. For example, I have seen calendars with week 53 that spans into the first few days of January the following year.
Only some months have 31 days. You do not appear to be comparing a specific calendar date with a real live calendar, but rather you are taking the number of days between two dates and then trying to match it up with a generic, artificial definition of weeks and months?
Do you need to determine the week number, the month number, both week and month numbers, or does it depend on something?
It looks like you have made assumptions that the number only falls into week 5 if the number is in range 29-31. And also that number only falls into month 2 starting with number = 32. What about leap years?
Calendars don't always work like that. Week and month definitions can vary based on business rules. For example, I have seen calendars with week 53 that spans into the first few days of January the following year.
Only some months have 31 days. You do not appear to be comparing a specific calendar date with a real live calendar, but rather you are taking the number of days between two dates and then trying to match it up with a generic, artificial definition of weeks and months?
Choose a job you love, and you will never have to work a day in your life. - Confucius
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Weeks is easy. And if you're only interested in 01/01/yyyy as the base date, then 31 is a reasonably day count figure to use.
Months, on the other hand, require you to extract the day number and month number, and compare these. Pertinent functions are MonthDayFromDate() and MonthFromDate().
Months, on the other hand, require you to extract the day number and month number, and compare these. Pertinent functions are MonthDayFromDate() and MonthFromDate().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.