Conteúdo do Curso
Google Spreadsheets
Google Spreadsheets
Working with Dates and Time
The TODAY function returns the current date in date format without the time. This is useful for automatically updating the date in calculations when the document is recalculated.
The NOW function returns the current date and time. This is useful for automatically tracking the exact time of updates or other operations.
Syntax and Examples
TODAY()
NOW()
Formula | Result | Comment |
---|---|---|
TODAY() | 9/30/2024 | The TODAY function returns the current date without time. The result will automatically update each day. |
NOW() | 9/30/2024 14:31:17 | The NOW function returns the current date and time. The value updates whenever the table is modified or opened. |
TODAY() + 7 | 10/7/2024 | When adding a number to TODAY, it is interpreted as the number of days. In this example, it returns the date 7 days from now. |
TEXT(NOW(), "HH:MM") | 14:31 | TEXT formats the NOW result to display only the time in HH:MM format. This is useful when working with time only. |
TEXT(TODAY(), "dddd") | Monday | TEXT formats the date into the full weekday name. In this case, it returns "Monday." |
IF(TODAY() = DATE(2024, 10, 1), "Today", "Not today") | Not today | The condition checks if today's date matches the specified date (October 1, 2024). If it matches, it returns "Today," otherwise "Not today." |
Working with Dates
The DATE function allows you to create a date from individual year, month, and day values. This is useful for combining values into a single date or for date calculations.
The DATEVALUE function converts a text string representing a date into a date format. This is useful when the date is written as a string, and you need to work with it as a numerical value for calculations.
Syntax and Examples
DATE(year, month, day)
- year - The year component of the date.
- month - The month component of the date;
- day - The day component of the date;
DATEVALUE(date_string)
- date_string - The string representing the date;
- Understood formats include any date format that is automatically converted when entered into a cell, without quotation marks. The formats may vary based on region and language settings.
Formula | Result | Comment |
---|---|---|
DATE(2024, 12, 31) | 12/31/2024 | Creates the date December 31, 2024, by combining the year, month, and day. |
DATE(2024.8, 2.7, 10) | 2/10/2024 | Fractional values are rounded to integers, creating the date February 10, 2024. |
DATE(2025, 1, 1) - DATE(2024, 1, 1) | 366 | The difference in days between January 1, 2024, and January 1, 2025, including the leap year. |
DATEVALUE("12/31/2024") | 12/31/2024 | Converts the text string "12/31/2024" into the date December 31, 2024. |
DATEVALUE("January 1, 2025") | 1/1/2025 | Converts the text "January 1, 2025" into the date January 1, 2025. |
DATEVALUE("2024-12-29") | 12/29/2024 | Converts the string "2024-12-29" into the date December 29, 2024. |
DATEVALUE("25-Dec-2024") | 12/25/2024 | Converts the text "25-Dec-2024" into the date December 25, 2024. |
IF(DATEVALUE("12/15/2024") < TODAY(), "Past", "Future") | Future | Checks whether December 15, 2024, is in the past or future relative to today. |
Working with Times
The TIME function allows you to create a time value from hours, minutes, and seconds. This is useful for working with time intervals or event calculations.
The TIMEVALUE function converts a text string representing time into a numerical time value. This is useful if the time is recorded as text, but you need to work with it as a numerical value.
Syntax and Examples
TIME(hour, minute, second)
- hour - The hour component of the time;
- minute - The minute component of the time;
- second - The second component of the time.
TIMEVALUE(time_string)
time_string - The string that holds the time representation.
Formula | Result | Comment |
---|---|---|
TIME(14, 30, 0) | 2:30:00 PM | Creates the time 14:30:00 (2:30 PM), where hours, minutes, and seconds are specified. |
TIME(9, 45, 30) | 9:45:30 AM | Creates the time 9:45:30 (AM). |
TIME(0, 0, 0) | 12:00:00 AM | Returns midnight (00:00:00), where all components are 0. |
TIMEVALUE("14:30:00") | 2:30:00 PM | The text time "14:30:00" is converted to 2:30 PM. |
TIMEVALUE("09:45:30 AM") | 9:45:30 AM | The text time "09:45:30 AM" is converted to 9:45 AM. |
TIMEVALUE("11:30 AM") | 11:30:00 AM | The time "11:30 AM" is converted to the numerical format 11:30:00 AM. |
IF(TIMEVALUE("5:59 PM") > TIMEVALUE("12:00 PM"), "Afternoon", "Morning") | Afternoon | The condition checks if 5:59 PM is later than 12:00 PM and returns "Afternoon." |
Extracting Year, Month, and Day
The YEAR function extracts the year from a date. This is useful when you need to separate the year for data analysis or filtering by year.
The MONTH function extracts the month from a date. This is useful for analyzing data by month or grouping data by months.
The DAY function returns the day of the month from a date. This is useful for filtering data by days or analyzing events that occurred on a specific day of the month.
Syntax and Examples
YEAR(date)
date - The date from which to calculate the year. Must be a cell reference to a cell containing a date, a function returning a date type, or a number.
MONTH(date)
date - The date from which to extract the month. Must be a reference to a cell containing a date, a function returning a date type, or a number.
DAY(date)
date - The date from which to extract the day. Must be a reference to a cell containing a date, a function returning a date type, or a number.
Formula | Result | Comment |
---|---|---|
YEAR(DATE(2024, 12, 31)) | 2024 | Extracts the year 2024 from the date December 31, 2024. |
MONTH(DATE(2024, 12, 31)) | 12 | Extracts the month 12 (December) from the date December 31, 2024. |
MONTH("12/31/2024") | 12 | Extracts the month 12 (December) from the date December 31, 2024, by another method. |
DAY(DATE(2024, 12, 31)) | 31 | Extracts the day 31 from the date December 31, 2024. |
YEAR(TODAY()) | 2024 | Returns the current year 2024 based on the TODAY function. |
MONTH(TODAY()) | 10 | Returns the current month (October) based on the TODAY function. |
DAY(TODAY()) | 1 | Returns the current day of the month (1) based on the TODAY function. |
IF(MONTH(DATE(2024, 12, 31)) = 12, "December", "Not December") | December | Checks if the month in the given date is December and returns "December." |
Obrigado pelo seu feedback!