Countif date includes year, month or day - date

I have a column containing dates in a Google sheet. How can I count the number of dates that include a specific year, month or day?
I have tried the following: =COUNTIF(G:G, YEAR(2000)) which just returns a zero, although there are multiple dates in the year 2000 in that column.
All the best!

year:
=INDEX(COUNTIF(YEAR(G:G), 2000))
month:
=INDEX(COUNTIF(MONTH(G:G), 11))
=INDEX(COUNTIFS(MONTH(G:G), 12, G:G, "<>"))
day:
=INDEX(COUNTIF(DAY(G:G), 27))
weekday:
=INDEX(COUNTIF(WEEKDAY(G:G, 1), 7))

Related

Subtracting 1 ISO 8601 year from a date in BigQuery

I'm trying to manipulate a date value to go back in time exactly 1 ISO-8601 year.
The following does not work, but best describes what I want to accomplish:
date_add(date '2018-01-03', interval -1 isoyear)
I tried string conversion as an intermediate step, but that doesn't work either:
select parse_date('%G%V%u',safe_cast(safe_cast(format_date('%G%V%u',date '2018-01-03') as int64)-1000 as string))
The error provided for the last one is "Failed to parse input string "2017013"". I don't understand why, this should always resolve to a unique date value.
Is there another way in which I can subtract an ISO year from a date?
This gives the corresponding day of the previous ISO year by subtracting the appropriate number of weeks from the date. I based the calculation on the description of weeks per year from the Wikipedia page:
CREATE TEMP FUNCTION IsLongYear(d DATE) AS (
-- Year starting on Thursday
EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 5 OR
-- Leap year starting on Wednesday
(EXTRACT(DAY FROM DATE_ADD(DATE(EXTRACT(YEAR FROM d), 2, 28), INTERVAL 1 DAY)) = 29
AND EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 4)
);
CREATE TEMP FUNCTION PreviousIsoYear(d DATE) AS (
DATE_SUB(d, INTERVAL IF(IsLongYear(d), 53, 52) WEEK)
);
SELECT PreviousIsoYear('2018-01-03');
This returns 2017-01-04, which is the third day of the 2017 ISO year. 2018-01-03 is the third day of the 2018 ISO year.

SharePoint custom list date and time validation

I have a custom list that I'm trying to restrict data entry for valid day of week and time.
My current column validation works for day of week being Monday, Wednesday or Friday. It looks like this:
=CHOOSE(WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE)
I'm trying to figure out the syntax to add that it also has to be between 8 am and 12:00 pm on those days.
Any help would be greatly appreciated.
You would use an AND statement to include a second criteria
=AND(CHOOSE(WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE),
AND(
[Requested date for approval]-INT([Requested date for approval])*24 >= 8,
[Requested date for approval]-INT([Requested date for approval])*24 <= 24
)
)
I confess, I've never heard of the CHOOSE function, but the time calculation is based on the information at Microsoft
Convert times
To convert hours from the standard time format to a decimal number, use the INT
function.
Column1 Formula Description (possible result)
10:35 AM =([Column1]-INT([Column1]))*24 Number of hours since 12:00 AM (10.583333)
12:15 PM =([Column1]-INT([Column1]))*24 Number of hours since 12:00 AM (12.25)
EDIT
To calculate the day of the week, you can use the TEXT function to return the day of the week (i.e. Monday)
=TEXT(WEEKDAY([ColumnName]), "dddd")
It won't be pretty, but you can use a series of AND logical operators
=AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Monday",
AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Wednesday",
AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Friday",
AND(
[Requested date for approval]-INT([Requested date for approval])*24 >= 8,
[Requested date for approval]-INT([Requested date for approval])*24 <= 24
)
)
)
)
Posting Working Solution
=IF(
AND(
CHOOSE(
WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE
),
([Requested date for approval]-INT([Requested date for approval]))*24>=8,
([Requested date for approval]-INT([Requested date for approval]))*24<=12
),
TRUE
)

SSRS expression, iif statement with date conditions

So my default values for startDate and endDate in SSRS were set up with the following ssrs expressions.
first day of previous month ssrs expression
=DateAdd(DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))
last day of previous month ssrs expression
=DateAdd(DateInterval.Day, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))
But that won't work alone in my case unless I want to go in on the 16th of every month and generate this report for the people requesting it for the first 15 days of the current month.
So in my default value expression for start date i am trying this iif statement...
= iif(
DatePart(DateInterval.Day, Today() <> "20",
DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1),
DateInterval.Month, 1, DateSerial(Year(Date.Now), Month(Date.Now), 1)
)
Not working out so well. So what i'm trying to do is.....
Change the default start and end date based on what day of the current month it is, So if current day of the current month equals 16, make start date 1 of current month and end date 15 of current month, if current day of the month isn’t 16 make start date first of previous month and end date last day of previous month. So then the only thing needed is to get subscription emails and what day to send them out on.
Untested, but what if you try this? (for your start date parameter):
= iif(
DatePart(DateInterval.Day, Today()) <> "16",
DateAdd(DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1)),
DateSerial(Year(Date.Now), Month(Date.Now), 1)
)

Crystal Reports show current month as a 2 digit field

I wonder if anyone could help on this please? I need to show the current month as a 2 digit field. IE
January as 01
February as 02
March as 03
etc until
October as 10
November as 11
December as 12
The formula I am using is: ToText ("0"& Month(CurrentDate))
but shows January as 01.00
ie need to remove the decimal point and the decimal places
Many thanks, Rob
Try this:
ToText( CurrentDate, "MM")
The ToText function will automatically convert the date you are supplying to whatever format you want. You don't need to use the Month function. Per the documentation, you just supply the date and the output format. For the month, you use "MM".
ToText(CurrentDate, "MM")
According to the documention, these are the valid strings you can use
Pattern Result
d Numeric day of month without leading zero (1, 7, 31)
dd Numeric day of month with leading zero (01, 07, 31)
ddd Three day abbreviation of day of week (Mon, Sat)
dddd Full name of day of week (Monday, Saturday)
M Numeric month without leading zero (1, 7, 12)
MM Numeric month with leading zero (01, 07, 12)
MMM Three letter abbreviation of month (Jan, Feb, Mar)
MMMM Full name of month (January, February, March)
yy Last two digits of year (11, 14, 22)
yyyy Full four digits of year (2011, 2014, 2022)
To add to the above, if you need to return something like Mar-17 then:
totext({Command.DocDate},"MMM") + '-' + totext({Command.DocDate},"yy")

Previous month in parameter

I need to set a Hidden Default Parameter in SSRS.
In my query I need to not show last months total but the month before that, ie in Feb I need to show Dec totals.
I usually use this for last month but cannot tweak it for the month prior.
Set first date of last month:
=DateAdd("m", -1, DateSerial(Year(Now()), Month(Now()), 1))
Set last date of last month:
=DateAdd("d", -1, DateSerial(Year(Now()), Month(Now()), 1))
If i understand you right you want to:
Get the first day of two months from now
=DateAdd("m", -2, DateSerial(Year(Now()), Month(Now()), 1))
And you want to get the last day on month two months from now
=DateAdd("d" , -1 , DateAdd("m", -1, DateSerial(Year(Now()), Month(Now()), 1)))
Depending on exactly what you need, use something like:
DateAdd
(
DateInterval.Month
, -1
, DateAdd(DateInterval.Day, -1, DateSerial(Year(Parameters!Date.Value), Month(Parameters!Date.Value), 1))
)
Used in a report: