Below are 140 examples of different date functions, including data, formulas, and nested functions. These examples cover a wide range of use cases for date manipulation in Excel, Google Sheets, or similar spreadsheet tools.
1. Basic Date Functions
TODAY(): Returns the current date.
Formula:
=TODAY()
Output:
10/25/2023
(if today's date is October 25, 2023)
NOW(): Returns the current date and time.
Formula:
=NOW()
Output:
10/25/2023 14:30
DATE(year, month, day): Creates a date from year, month, and day.
Formula:
=DATE(2023, 10, 25)
Output:
10/25/2023
DAY(date): Extracts the day from a date.
Formula:
=DAY("10/25/2023")
Output:
25
MONTH(date): Extracts the month from a date.
Formula:
=MONTH("10/25/2023")
Output:
10
YEAR(date): Extracts the year from a date.
Formula:
=YEAR("10/25/2023")
Output:
2023
WEEKDAY(date): Returns the day of the week (1 = Sunday, 7 = Saturday).
Formula:
=WEEKDAY("10/25/2023")
Output:
4
(Wednesday)
WEEKNUM(date): Returns the week number of the year.
Formula:
=WEEKNUM("10/25/2023")
Output:
43
EDATE(start_date, months): Adds months to a date.
Formula:
=EDATE("10/25/2023", 2)
Output:
12/25/2023
EOMONTH(start_date, months): Returns the last day of the month after adding months.
Formula:
=EOMONTH("10/25/2023", 0)
Output:
10/31/2023
2. Date Arithmetic
Add days to a date:
Formula:
="10/25/2023" + 7
Output:
11/01/2023
Subtract days from a date:
Formula:
="10/25/2023" - 10
Output:
10/15/2023
Difference between two dates in days:
Formula:
="10/25/2023" - "10/10/2023"
Output:
15
Difference between two dates in months:
Formula:
=DATEDIF("10/10/2023", "10/25/2023", "m")
Output:
0
Difference between two dates in years:
Formula:
=DATEDIF("10/10/2020", "10/25/2023", "y")
Output:
3
Add months to a date:
Formula:
=EDATE("10/25/2023", 5)
Output:
03/25/2024
Subtract months from a date:
Formula:
=EDATE("10/25/2023", -3)
Output:
07/25/2023
Add years to a date:
Formula:
=DATE(YEAR("10/25/2023") + 2, MONTH("10/25/2023"), DAY("10/25/2023"))
Output:
10/25/2025
Subtract years from a date:
Formula:
=DATE(YEAR("10/25/2023") - 1, MONTH("10/25/2023"), DAY("10/25/2023"))
Output:
10/25/2022
Calculate age from birthdate:
Formula:
=DATEDIF("05/15/1990", TODAY(), "y")
Output:
33
(if today is October 25, 2023)
3. Nested Date Functions
Extract the day of the week name:
Formula:
=TEXT(WEEKDAY("10/25/2023"), "dddd")
Output:
Wednesday
Get the first day of the month:
Formula:
=DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1)
Output:
10/01/2023
Get the last day of the month:
Formula:
=EOMONTH("10/25/2023", 0)
Output:
10/31/2023
Check if a date is a weekend:
Formula:
=IF(OR(WEEKDAY("10/25/2023")=1, WEEKDAY("10/25/2023")=7), "Weekend", "Weekday")
Output:
Weekday
Calculate the next Monday from a date:
Formula:
="10/25/2023" + (8 - WEEKDAY("10/25/2023"))
Output:
10/30/2023
Calculate the previous Friday from a date:
Formula:
="10/25/2023" - (WEEKDAY("10/25/2023") + 1)
Output:
10/20/2023
Check if a year is a leap year:
Formula:
=IF(MONTH(DATE(YEAR("10/25/2023"), 2, 29))=2, "Leap Year", "Not Leap Year")
Output:
Not Leap Year
Get the quarter of the year for a date:
Formula:
=ROUNDUP(MONTH("10/25/2023")/3, 0)
Output:
4
Calculate the number of workdays between two dates:
Formula:
=NETWORKDAYS("10/10/2023", "10/25/2023")
Output:
12
Calculate the number of workdays excluding holidays:
Formula:
=NETWORKDAYS("10/10/2023", "10/25/2023", {"10/12/2023", "10/19/2023"})
Output:
10
4. Advanced Date Functions
Convert a text string to a date:
Formula:
=DATEVALUE("10/25/2023")
Output:
10/25/2023
Convert a date to a text string:
Formula:
=TEXT("10/25/2023", "mmmm dd, yyyy")
Output:
October 25, 2023
Extract the day name from a date:
Formula:
=TEXT("10/25/2023", "dddd")
Output:
Wednesday
Extract the month name from a date:
Formula:
=TEXT("10/25/2023", "mmmm")
Output:
October
Calculate the end of the current quarter:
Formula:
=EOMONTH("10/25/2023", 3 - MONTH("10/25/2023") %% 3)
Output:
12/31/2023
Calculate the start of the next quarter:
Formula:
=EOMONTH("10/25/2023", 3 - MONTH("10/25/2023") %% 3) + 1
Output:
01/01/2024
Calculate the number of days remaining in the month:
Formula:
=EOMONTH("10/25/2023", 0) - "10/25/2023"
Output:
6
Calculate the number of days remaining in the year:
Formula:
=DATE(YEAR("10/25/2023"), 12, 31) - "10/25/2023"
Output:
67
Calculate the number of days since the start of the year:
Formula:
="10/25/2023" - DATE(YEAR("10/25/2023"), 1, 1)
Output:
297
Calculate the number of days until a specific date:
Formula:
="12/31/2023" - "10/25/2023"
Output:
67
5. Conditional Date Functions
Check if a date is in the past:
Formula:
=IF("10/25/2023" < TODAY(), "Past", "Future")
Output:
Past
(if today is October 26, 2023)
Check if a date is in the current month:
Formula:
=IF(MONTH("10/25/2023") = MONTH(TODAY()), "Current Month", "Other Month")
Output:
Current Month
(if today is October 2023)
Check if a date is in the current year:
Formula:
=IF(YEAR("10/25/2023") = YEAR(TODAY()), "Current Year", "Other Year")
Output:
Current Year
(if today is 2023)
Check if a date is a weekday:
Formula:
=IF(WEEKDAY("10/25/2023", 2) < 6, "Weekday", "Weekend")
Output:
Weekday
Check if a date is a holiday:
Formula:
=IF(OR("10/25/2023" = "12/25/2023", "10/25/2023" = "01/01/2024"), "Holiday", "Not Holiday")
Output:
Not Holiday
6. Date Formatting
Format a date as "YYYY-MM-DD":
Formula:
=TEXT("10/25/2023", "yyyy-mm-dd")
Output:
2023-10-25
Format a date as "DD/MM/YYYY":
Formula:
=TEXT("10/25/2023", "dd/mm/yyyy")
Output:
25/10/2023
Format a date as "Month DD, YYYY":
Formula:
=TEXT("10/25/2023", "mmmm dd, yyyy")
Output:
October 25, 2023
Format a date as "Day, Month DD, YYYY":
Formula:
=TEXT("10/25/2023", "dddd, mmmm dd, yyyy")
Output:
Wednesday, October 25, 2023
Format a date as "YYYYMMDD":
Formula:
=TEXT("10/25/2023", "yyyymmdd")
Output:
20231025
7. Complex Nested Date Functions
Calculate the last Friday of the month:
Formula:
=EOMONTH("10/25/2023", 0) - WEEKDAY(EOMONTH("10/25/2023", 0) + 1) + 6
Output:
10/27/2023
Calculate the first Monday of the month:
Formula:
=DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1) + MOD(8 - WEEKDAY(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1)), 7)
Output:
10/02/2023
Calculate the number of Sundays in a month:
Formula:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1) & ":" & EOMONTH("10/25/2023", 0))))=1))
Output:
4
Calculate the number of weekdays in a month:
Formula:
=NETWORKDAYS(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1), EOMONTH("10/25/2023", 0))
Output:
22
Calculate the number of weekends in a month:
Formula:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1) & ":" & EOMONTH("10/25/2023", 0))))=1)) + SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1) & ":" & EOMONTH("10/25/2023", 0))))=7))
Output:
8
8. Date Functions with Time
Extract the time from a datetime:
Formula:
=MOD("10/25/2023 14:30", 1)
Output:
0.604166667
(2:30 PM)
Add hours to a datetime:
Formula:
="10/25/2023 14:30" + TIME(3, 0, 0)
Output:
10/25/2023 17:30
Subtract hours from a datetime:
Formula:
="10/25/2023 14:30" - TIME(2, 0, 0)
Output:
10/25/2023 12:30
Calculate the difference in hours between two datetimes:
Formula:
=("10/25/2023 17:30" - "10/25/2023 14:30") * 24
Output:
3
Calculate the difference in minutes between two datetimes:
Formula:
=("10/25/2023 17:30" - "10/25/2023 14:30") * 1440
Output:
180
9. Date Functions with Arrays
Create a list of dates for a month:
Formula:
=SEQUENCE(31, 1, DATE(2023, 10, 1), 1)
Output:
10/01/2023, 10/02/2023, ..., 10/31/2023
Create a list of weekdays for a month:
Formula:
=FILTER(SEQUENCE(31, 1, DATE(2023, 10, 1), 1), WEEKDAY(SEQUENCE(31, 1, DATE(2023, 10, 1), 1), 2) < 6)
Output:
10/02/2023, 10/03/2023, ..., 10/31/2023
(excluding weekends)
Create a list of weekends for a month:
Formula:
=FILTER(SEQUENCE(31, 1, DATE(2023, 10, 1), 1), WEEKDAY(SEQUENCE(31, 1, DATE(2023, 10, 1), 1), 2) > 5)
Output:
10/01/2023, 10/07/2023, ..., 10/29/2023
Create a list of dates for the next 7 days:
Formula:
=SEQUENCE(7, 1, TODAY(), 1)
Output:
10/25/2023, 10/26/2023, ..., 10/31/2023
Create a list of dates for the previous 7 days:
Formula:
=SEQUENCE(7, 1, TODAY() - 7, 1)
Output:
10/18/2023, 10/19/2023, ..., 10/24/2023
10. Date Functions with Logical Conditions
Check if a date is within a range:
Formula:
=IF(AND("10/25/2023" >= "10/01/2023", "10/25/2023" <= "10/31/2023"), "Within Range", "Out of Range")
Output:
Within Range
Check if a date is a leap year:
Formula:
=IF(MONTH(DATE(YEAR("10/25/2023"), 2, 29))=2, "Leap Year", "Not Leap Year")
Output:
Not Leap Year
Check if a date is the last day of the month:
Formula:
=IF("10/25/2023" = EOMONTH("10/25/2023", 0), "Last Day", "Not Last Day")
Output:
Not Last Day
Check if a date is the first day of the month:
Formula:
=IF("10/25/2023" = DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1), "First Day", "Not First Day")
Output:
Not First Day
Check if a date is a specific day of the week:
Formula:
=IF(WEEKDAY("10/25/2023") = 4, "Wednesday", "Not Wednesday")
Output:
Wednesday
11. Date Functions with Lookups
Find the closest date in a list:
Formula:
=INDEX(A1:A10, MATCH(MIN(ABS(A1:A10 - "10/25/2023")), ABS(A1:A10 - "10/25/2023"), 0))
Output:
10/24/2023
(if 10/24/2023 is the closest date in the list)
Find the latest date in a list:
Formula:
=MAX(A1:A10)
Output:
10/31/2023
(if 10/31/2023 is the latest date in the list)
Find the earliest date in a list:
Formula:
=MIN(A1:A10)
Output:
10/01/2023
(if 10/01/2023 is the earliest date in the list)
Find the date with the highest value in another column:
Formula:
=INDEX(A1:A10, MATCH(MAX(B1:B10), B1:B10, 0))
Output:
10/25/2023
(if 10/25/2023 has the highest value in column B)
Find the date with the lowest value in another column:
Formula:
=INDEX(A1:A10, MATCH(MIN(B1:B10), B1:B10, 0))
Output:
10/01/2023
(if 10/01/2023 has the lowest value in column B)
12. Date Functions with Aggregations
Count the number of dates in a list:
Formula:
=COUNT(A1:A10)
Output:
10
(if there are 10 dates in the list)
Count the number of dates in a specific month:
Formula:
=SUMPRODUCT(--(MONTH(A1:A10) = 10))
Output:
5
(if there are 5 dates in October)
Count the number of dates in a specific year:
Formula:
=SUMPRODUCT(--(YEAR(A1:A10) = 2023))
Output:
10
(if all dates are in 2023)
Sum values for a specific month:
Formula:
=SUMPRODUCT((MONTH(A1:A10) = 10) * B1:B10)
Output:
500
(if the sum of values in column B for October is 500)
Average values for a specific month:
Formula:
=AVERAGEIF(A1:A10, ">=10/01/2023", B1:B10)
Output:
50
(if the average of values in column B for October is 50)
13. Date Functions with Conditional Formatting
Highlight dates in the past:
Formula:
=A1 < TODAY()
Output: Highlights dates before today.
Highlight dates in the future:
Formula:
=A1 > TODAY()
Output: Highlights dates after today.
Highlight weekends:
Formula:
=OR(WEEKDAY(A1) = 1, WEEKDAY(A1) = 7)
Output: Highlights Saturdays and Sundays.
Highlight holidays:
Formula:
=OR(A1 = "12/25/2023", A1 = "01/01/2024")
Output: Highlights specific holidays.
Highlight dates within a range:
Formula:
=AND(A1 >= "10/01/2023", A1 <= "10/31/2023")
Output: Highlights dates in October 2023.
14. Date Functions with Text Manipulation
Extract the year from a date string:
Formula:
=LEFT("10/25/2023", 4)
Output:
2023
Extract the month from a date string:
Formula:
=MID("10/25/2023", 4, 2)
Output:
10
Extract the day from a date string:
Formula:
=RIGHT("10/25/2023", 2)
Output:
25
Combine text and dates:
Formula:
="Today is " & TEXT(TODAY(), "mmmm dd, yyyy")
Output:
Today is October 25, 2023
Convert a date string to a different format:
Formula:
=TEXT("10/25/2023", "dd-mmm-yy")
Output:
25-Oct-23
15. Date Functions with Error Handling
Check if a date is valid:
Formula:
=IF(ISDATE("10/25/2023"), "Valid", "Invalid")
Output:
Valid
Handle invalid dates:
Formula:
=IFERROR(DATEVALUE("13/25/2023"), "Invalid Date")
Output:
Invalid Date
Check if a date is blank:
Formula:
=IF(ISBLANK(A1), "Blank", "Not Blank")
Output:
Blank
(if A1 is empty)
Replace invalid dates with a default value:
Formula:
=IF(ISDATE(A1), A1, "01/01/2023")
Output:
01/01/2023
(if A1 is invalid)
Check if a date is within a valid range:
Formula:
=IF(AND(A1 >= "01/01/2023", A1 <= "12/31/2023"), "Valid", "Invalid")
Output:
Valid
(if A1 is within 2023)
16. Date Functions with Custom Logic
Calculate the next business day:
Formula:
=WORKDAY("10/25/2023", 1)
Output:
10/26/2023
Calculate the previous business day:
Formula:
=WORKDAY("10/25/2023", -1)
Output:
10/24/2023
Calculate the number of business days between two dates:
Formula:
=NETWORKDAYS("10/10/2023", "10/25/2023")
Output:
12
Calculate the number of business days excluding holidays:
Formula:
=NETWORKDAYS("10/10/2023", "10/25/2023", {"10/12/2023", "10/19/2023"})
Output:
10
Calculate the number of business days in a month:
- Formula:=NETWORKDAYS(DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1), EOMONTH("10/25/2023", 0))
- Output:22
17. Date Functions with Time Zones
Convert a datetime to UTC:
- Formula:="10/25/2023 14:30" - TIME(5, 0, 0)
- Output:10/25/2023 09:30
(if converting from EST to UTC)Convert a datetime from UTC to local time:
- Formula:="10/25/2023 14:30" + TIME(5, 0, 0)
- Output:10/25/2023 19:30
(if converting from UTC to EST)Calculate the time difference between two time zones:
- Formula:=TIME(5, 0, 0) - TIME(3, 0, 0)
- Output:02:00
Adjust a datetime for daylight saving time:
- Formula:="10/25/2023 14:30" - TIME(1, 0, 0)
- Output:10/25/2023 13:30
(if adjusting for DST)Calculate the current time in a different time zone:
- Formula:=NOW() + TIME(5, 0, 0)
- Output:10/25/2023 19:30
(if converting from UTC to EST)
18. Date Functions with Financial Calculations
Calculate the number of days between two dates for interest calculation:
- Formula:="10/25/2023" - "10/10/2023"
- Output:15
Calculate the number of days in a year for interest calculation:
- Formula:=DATE(YEAR("10/25/2023"), 12, 31) - DATE(YEAR("10/25/2023"), 1, 1)
- Output:364
Calculate the number of days in a month for interest calculation:
- Formula:=EOMONTH("10/25/2023", 0) - DATE(YEAR("10/25/2023"), MONTH("10/25/2023"), 1)
- Output:30
Calculate the number of days between two dates for bond pricing:
- Formula:="10/25/2023" - "10/10/2023"
- Output:15
Calculate the number of days in a quarter for financial reporting:
- Formula:=EOMONTH("10/25/2023", 3 - MONTH("10/25/2023") %% 3) - DATE(YEAR("10/25/2023"), MONTH("10/25/2023") - MOD(MONTH("10/25/2023") - 1, 3), 1)
- Output:92
19. Date Functions with Project Management
Calculate the end date of a project:
- Formula:="10/25/2023" + 30
- Output:11/24/2023
Calculate the start date of a project:
- Formula:="10/25/2023" - 30
- Output:09/25/2023
Calculate the number of workdays in a project:
- Formula:=NETWORKDAYS("10/25/2023", "11/24/2023")
- Output:23
Calculate the number of workdays excluding holidays:
- Formula:=NETWORKDAYS("10/25/2023", "11/24/2023", {"11/11/2023", "11/23/2023"})
- Output:21
Calculate the number of weekends in a project:
- Formula:=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT("10/25/2023" & ":" & "11/24/2023"))) > 5))
- Output:8
20. Date Functions with Data Validation
Restrict input to dates in the future:
- Formula:=A1 > TODAY()
- Output: Allows only future dates.Restrict input to dates in the past:
- Formula:=A1 < TODAY()
- Output: Allows only past dates.Restrict input to dates within a specific range:
- Formula:=AND(A1 >= "10/01/2023", A1 <= "10/31/2023")
- Output: Allows only dates in October 2023.Restrict input to weekdays:
- Formula:=WEEKDAY(A1, 2) < 6
- Output: Allows only weekdays.Restrict input to specific holidays:
- Formula:=NOT(OR(A1 = "12/25/2023", A1 = "01/01/2024"))
- Output: Allows only non-holiday dates.
21. Date Functions with Pivot Tables
Group dates by month in a pivot table:
- Formula:=TEXT(A1, "mmmm")
- Output:October
Group dates by quarter in a pivot table:
- Formula:="Q" & ROUNDUP(MONTH(A1)/3, 0)
- Output:Q4
Group dates by year in a pivot table:
- Formula:=YEAR(A1)
- Output:2023
Group dates by week in a pivot table:
- Formula:=WEEKNUM(A1)
- Output:43
Group dates by day of the week in a pivot table:
- Formula:=TEXT(A1, "dddd")
- Output:Wednesday
22. Date Functions with Charts
Create a line chart with dates on the x-axis:
- Formula:=A1:A10
(dates) and=B1:B10
(values)
- Output: A line chart with dates on the x-axis.Create a bar chart with dates on the x-axis:
- Formula:=A1:A10
(dates) and=B1:B10
(values)
- Output: A bar chart with dates on the x-axis.Create a scatter plot with dates on the x-axis:
- Formula:=A1:A10
(dates) and=B1:B10
(values)
- Output: A scatter plot with dates on the x-axis.Create a histogram with dates:
- Formula:=A1:A10
(dates)
- Output: A histogram with dates.Create a Gantt chart with dates:
- Formula:=A1:A10
(start dates) and=B1:B10
(end dates)
- Output: A Gantt chart.
23. Date Functions with Macros
Automate date entry with a macro:
- Formula:=TODAY()
- Output: Automatically enters today's date.Automate date formatting with a macro:
- Formula:=TEXT(A1, "mmmm dd, yyyy")
- Output: Automatically formats dates.Automate date calculations with a macro:
- Formula:=A1 + 7
- Output: Automatically adds 7 days to a date.Automate date validation with a macro:
- Formula:=IF(A1 < TODAY(), "Past", "Future")
- Output: Automatically validates dates.Automate date filtering with a macro:
- Formula:=FILTER(A1:A10, A1:A10 >= "10/01/2023")
- Output: Automatically filters dates.
24. Date Functions with External Data
Import dates from a CSV file:
- Formula:=IMPORTDATA("dates.csv")
- Output: Imports dates from a CSV file.Import dates from a database:
- Formula:=QUERY("SELECT date FROM table", "where date >= '10/01/2023'")
- Output: Imports dates from a database.Import dates from a web page:
- Formula:=IMPORTHTML("https://example.com", "table", 1)
- Output: Imports dates from a web page.Import dates from an API:
- Formula:=IMPORTJSON("https://api.example.com/dates", "/dates")
- Output: Imports dates from an API.Import dates from Google Sheets:
- Formula:=IMPORTRANGE("https://docs.google.com/spreadsheets/d/12345", "Sheet1!A1:A10")
- Output: Imports dates from another Google Sheet.
These examples cover a wide range of date-related tasks, from basic calculations to advanced manipulations and integrations
No comments:
Post a Comment