I am trying to create a weekly report (including grouping by WEEK(date)) where weeks start on Monday. However, Week 1 is always the first week any day of a new year occurs. For example if Jan 1st is a Friday, that is week one.
This doesn't seem to be consistent with MySQL mode options for WEEK():
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
Based on the available options it only works if the week has 4 or more days (options 1 and 3) or the Monday is in the new year (options 5 and 7). Neither of these account for example week 1 of 2016:
Wk Mon Tue Wed Thu Fri Sat Sun
No.
1 28 29 30 31 1 2 3
Is there any way to order/number the week numbers in MySQL based on this custom week mode requirement?
Related
I currently have a monthly list of generated revenue but it is incorrectly accounted for and I have to change the dates to the previous month. For example, December revenue actually corresponds to November, May to April, February to January... and so on historically over the years.
The table I have made from groupings by month and year is the following:
Month
2021
2022
1
7.582
7.242
2
2.456
2.992
3
34.513
4.566
4
57.433
9.991
5
35.788
8.689
6
52.466
7.600
7
35.657
26.246
8
44.673
54.345
9
92.376
57.885
10
3.444
86.685
11
34.788
67.246
12
0
57.378
Which approach should I use in this case? I am using Metabase.
I have an SSRS report with the following header,
Date 28-Mar 27-Mar 25-Mar 24-Mar 23-Mar 22-Mar 21-Mar 20-Mar
Day Fri Thu Wed Tue Mon Sun Sat Fri
Pending 1 2 3 4 5 5 5 6
I able to generate Date and Day rows using expression with current date.
(e.g. = Left(WeekDayName(WeekDay(DateAdd("d",-1,Now()))),3))
But Pending Days row should display age in days with same age number for Mon, Sun and Sat since Sun and Sat are off days.
Is it possible to generate with expression?
Got it Guys,
We just need to make sum of no of 'mon', 'tus'..'fir' in the date range.
=DATEDIFF("ww",DateAdd("d",-1,Now()),Now(), vbMonday)
+
DATEDIFF("ww",DateAdd("d",-1,Now()),Now(), vbTuesday)
etc.
:)
I have a report in SSRS 2012 scheduled to run quarterly on a specific day i.e. 15th Jan, 15th Apr, 15th Jul & 15th Oct.
My shared schedule config is: Ticked 'Month', selected Jan, Apr, Jul & Oct, set 'On calendar day(s)' to '15'.
The schedule is displayed correctly but in fact runs on the 15th of each month.
Knowing these schedules are actually implemented using SQL Server Agent I inspect the job and find that the job in question has 4 schedules against it.
15th day of every 12 month starting on the 1 jan 2013
15th day of every 12 month starting on the 1 apr 2013
15th day of every 12 month starting on the 1 jul 2013
15th day of every 12 month starting on the 1 oct 2013
so that also makes sense.
Is there a fix to this issue?
I think the problem (and solution) is the same as described here https://techcommunity.microsoft.com/t5/System-Center-Blog/Support-Tip-Scheduled-backup-to-tape-runs-on-a-wrong-date-on-DPM/ba-p/347075
I use mySql 5 and IIS.
I have products, that have a start date field and an end date field.
I need to run a query that will take user entered Start and End dates, and output the number of days that the product ran within the date range.
Example:
Offer1 - July 1 2011 thru July 31 2011
Query - July 1 2011 thru Sept 15 2011
Results = 31
Example:
Offer1 - July 1 2011 thru July 31 2011
Query - July 1 2011 thru July 15 2011
Results = 15
If your products have a start_date and an end_date and your query has a qstart_date and a qend_date, then we want the number of days between:
GREATEST(start_date, qstart_date)
and
LEAST(end_date,qend_date)
. In MySQL I think this looks like
1 + DATEDIFF ( 'd' , GREATEST(start_date, qstart_date) , LEAST(end_date,qend_date) )
And you'll want to ignore negative numbers, replacing them with "0".
Does anyone know a way to convert a month, year, and day into the day's name for any year? Example:
function convert(day, year, month)
...
return "Monday"
end
Thanks in advance!
You can use the following method:
This method uses codes for different
months and years to speed up the
calculation of the day of the week.
You might even be able to memorize the
codes. We'll use December 16, 2482 as
an example.
Take the last 2 digits of the year. In
our example, this is 82.
Divide by 4, and drop any remainder.
82 / 4 = 20, remainder 2, so we think
"20."
Add the day of the month. In our
example, 20 + 16 = 36.
Add the month's key value, from the
following table. Jan Feb Mar Apr May
June July Aug Sept Oct Nov Dec 1 4 4
0 2 5 0 3 6 1 4 6
The month for our example is December,
with a key value of 6. 36 + 6 = 42.
If your date is in January or February
of a leap year, subtract 1. We're
using December, so we don't have to
worry about this step.
Add the century code from the
following table. (These codes are for
the Gregorian calendar. The rule's
slightly simpler for Julian dates.)
1700s 1800s 1900s 2000s 4 2 0 6
Our example year is 2482, and the
2400s aren't in the table. Luckily,
the Gregorian calendar repeats every
four hundred years. All we have to do
is add or subtract 400 until we have a
date that is in the table. 2482 - 400
= 2082, so we look at the table for the 2000s, and get the code 6. Now we
add this to our running total: 42 + 6
= 48.
Add the last two digits of the year.
48 + 82 = 130.
Divide by 7 and take the remainder.
This time, 1 means Sunday, 2 means
Monday, and so on. A remainder of 0
means Saturday.
How to calculate the day of the week
A quickl google for "day of week from date algorithm" showed up this Wikipedia article
But depending on the dates you need to work with, beware the strange history of Gregorian calendar adoption