I have a 200 data files to process. I need a solution for one of the files and I would do same for the rest of the files. It is a typical daily time series problem.
My rainfall data is arranged thus: 1990 to 2011 as years, under each year are 12 months, and in front of each month are 29 or 30 or 31 days depending on the month.
My problem is to take all the days in each month and place them beneath that month and for each year. The result will be two column vectors; one for dates and one for rainfall on each day, in each month in each year.
Thanks in advance.
Asong.
my data is shaped as:
1960 1 2 3 4 5 6 4
1961 1 2 3 4 5 6 4
and I want it to be 1960
1
.
.
N
1961
1
.
.
N
etc. as a column not row form.
I got the answer using reshape(a.',1,[]).
However, one problem remains. My data contains 31 days in all months. How can I tell matlab to delete last two or three days in February and one day in April and other months which are supposed to have 30 days but have 31 in my time series?
Related
Activity
Employee
Week of May 17
Week of May 24
Inbox
Alice
3
4
Inbox
Jane
5
8
Alpha Project
Alice
10
3
Beta Project
Francis
7
5
Chi Project
Jane
4
3
I've attempted to use conditional formatting, arrays & Vlookups and unable to cleanly get the following end result.
The End result is to flag anybody working > 10 hours for a given week.
Table is above.
End result should change the color of a cell titled "Alice" outside of this table because Alice worked 13 hours during Week of May 17.
End result should change the color of a cell titled "Jane" outside of this table because Jane worked 11 hours during Week of May 24.
Francis worked 10 hours or below, so no action is needed.
Any help on this is much appreciated --
Create a condition with the following formula:
=SUMIF(B2:B6,F2,C2:C6)>10
Where B2:B6 is the column of Employee names, F2 is the cell you want coloured, and C2:C6 is the column of the May 17th week
I am trying to calculate the number of days that have passed between 1/1/1900 and 5/1/2019.
I have tried this using several dates and get the same out come.
The value returned is 2 days off.
--
-- calculate the number of days between 1/1/1900 and 5/1/2018
--
SELECT DATEDIFF(DAY,CONVERT(DATE,'1/1/1900'),CONVERT(DATE,'5/1/2018'))
Expected Result: 43221
Actual Result: 43219
Thank you for your help!
DATEDIFF returns the number of days between the two dates. So if you want 1900-01-01 to be numbered as day 1, then you must add 1 to any difference you get from DATEDIFF. In Excel, day 0 is 1899-12-31.
Secondly, Excel treats 1900 as a leap year, and has a 29-Feb-1900 (day 60 in the Excel numbering system iirc). This was a holdover from Lotus 1-2-3 which originally used a simplified algorithm for leap years (treating every year divisible by 4 as a leap), and remains for backward compatibility
If you combine these two faults, these account for your off-by-two results.
Disclaimer: I am just looking for a logic not code
John discovered a strange island called Rasa. The years and weeks on the island are weird. Digging deeper into the island's calendar, he found out that it is similar to rest-of-the-world's (ROW) calendar but the island calendar's Year starts on 1st week of February's calendar. John is asking you to help him solve the problem of converting ROW's calendar into Island's calendar. Here is the question.
You are given a date (today's date). You have to determine the Island week's number. The catch here is that the Island year starts from 1st week of February and every Island's week starts from Sunday and ends on a Saturday. Write a SQL statement in SQL Server to achieve this. Use SQL Server functions and devise a logic.
Input parameter: Any date.
Output parameter: Week No in Rasa Calendar.
Here is an example:
Date: 5th May 2015 --
Week No in ROW Calendar:19
Week No in Rasa's Calendar:14
Date: Jan 1 2017:
Week No in ROW Calendar:1
Week No in Rasa's Calendar:49
My question: can this be achieved in SQL Server?
My homework: I tried a couple of ways to solve the problem.
Approach #1:
Step 1: Calculate the total no of days between today and Feb 1.
Step 2: Divide it by 7 and add 1 to the result.
Later found out that this approach will not work if Feb 1 is on any day other than Sunday.
Eg: 1st Feb is on Wednesday. 5th Feb will be on Monday
So, 1st Feb is on Rasa's week 1, and 5th Feb is on Rasa's week no 2. According to my approach 1st and 5th feb are on week 1 which is incorrect.
Approach #2:
I thought removing 5 weeks of Jan from ROW's calendar should work
select
case
when f.RasaWeek = -4 then 48
when f.RasaWeek = -3 then 49
when f.RasaWeek = -2 then 50
when f.RasaWeek = -1 then 51
when f.RasaWeek = 0 then 52
else
f.RasaWeek
end as Rasa_week,
f.year, f.month, f.date
from
(select
datepart(wk, date) - 5 as RasaWeek, *
from
<datetable>
where
Year(date) in (2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018)) as f
Info: I tested this on a <datetable> but this code will break if there is a 53rd week. Notice that I was not able to take care of the 53rd week.
Any inputs to solve this problem are welcome.
With dates, it's almost always easier to make a calendar table and store the data you care about rather than trying to do anything beyond basic date arithmetic. Use SQL's strengths: storing and retrieving data.
In this case, what you care about are all of the first Sundays in February. If you store these dates in a table, the solution is:
RETURN
SELECT TOP 1
DATEDIFF(day,[date],#input_date) / 7
FROM IslandCalendarStartDates
WHERE [date] <= #input
ORDER BY [date] DESC
This way you don't need to worry about leap years or 53-weeks, or any of the edge cases. Just count the days from the most recent first Sunday in February and divide by 7. If you need to change the solution to accommodate a different start date, you only change the data, not the code.
I am using the timeAgoInWords function in cakephp and I would like to know if there is a way to stop at the first time value, here is what I mean.
I have this code so far...
echo $this->Time->timeAgoInWords($post['created'],array('accuracy'=>array('day'=>'day')));
And some of my posts have a date that says 5 days ago while some others have 1 week, 5 days ago
How can I get all instances to stop at the first value so that 1 week, 5 days ago will just say 1 week ago
Keeping in mind that later on that some 1 week item may say 1 month ago instead of 1 month, 2 weeks, 7 days ago
Just specify the accuracy of each possible states :
accuracy'=>array('day'=>'day','week'=>'week','month'=>'month','year'=>'year')
I want to make a user defined function for calculating the month number from date.
But the problem is that I have the months numbered as 1, 2, 3 ... and each month is of 26 days, that makes a total of 13 months in the year, rather than 12
any useful help?
I'm not going to ask you why you'd want to do this. But here we go:
select convert(int, (datepart(Dayofyear, #date)-1)/26.0)+1