How to Extract Date or Time from Datetime in Excel
Are you tired of trying to extract date or time from datetime values in Excel? This post will show you how it’s done. Whether you need to separate the date component, the time component, or both, this guide has you covered. You’ll learn how to use formulas and functions to easily extract date or time from datetime values in Excel.
This post will guide you how to extract time from a data and time value with a formula in Excel. How do I extract time from a date-time number in Excel 2013/2016. How to extract hour only from the date time format in Excel.
Table of Contents
- 1. Extract Date from Datetime
- 2. Extract Date from Text String
- 3. Extract Year from Date
- 4. Concatenate Date and Time
- 5. Extract Time from Date and Time
- 6. Extract Hour only from Date and Time
- 7. Split Date and Time in Excel
- 8. Convert Unix Timestamp to a Date in Excel
- 9. If function with dates
- 10. Time Calculations in Excel
- 11. Conclusion
- 12. Related Functions
1. Extract Date from Datetime
To extract or get the date from a datetime value in one cell in Excel, you can use the following formula:
You need to replace “
datetime” with the cell reference that contains the datetime value. This formula converts the datetime value to text in the desired date format (
MM/DD/YYYY in this case).
The result will be the date part of the datetime value, displayed as text string. If you need to use the result in further calculations, you can convert the result back to a date value by using the “DATEVALUE” function.
You can also use the “=INT()” function to convert a date and time to a date:
This function will return the date portion of the date and time value as a serial number, which can be formatted as a date using the “Number Format” option in the “Home” tab of the Excel ribbon.
2. Extract Date from Text String
To extract the date from a text string in Excel, you can use the following formula:
where A1 is the cell that contains the text string.
This formula uses the SEARCH function to locate the position of the date part in the string and the MID function to extract the date part of the string.
3. Extract Year from Date
If you wish to extract the year part from a date value in Excel, you can use the YEAR function.
The YEAR function takes a date as an argument and returns the year component of the date, as a number.
For example, if cell
A1 contains the date “
02/08/2022“, you can extract the year using the following formula:
This formula will return the year “
4. Concatenate Date and Time
If you want to concatenate date and time in Microsoft Excel, you can use the “&” operator in combination with TEXT function to join the values in separate cells into one cell.
The Steps are as below:
Step 1: Enter the following formula in a empty cell:
=TEXT(A2,"MM/DD/YYYY") & " " & TEXT(B2,"HH:MM:SS")
- Replace A2 and B2 with the cells that contain your date and time, respectively.
- The formula uses the TEXT function to format the date and time values, and then joins them with a space in between.
Step 2: Press Enter to see the result of the formula.
Step 3: If you want to copy the result to multiple cells, simply select the cell with the formula, and then drag the fill handle to the cells you want to copy the formula to.
Your date and time values should now be combined into one cell in the format of “MM/DD/YYYY HH:MM:SS“.
5. Extract Time from Date and Time
If you want to extract time from a date and time in Excel, you can use a formula based on the TIME function, The HOUR function, the MINUTE function, and the SECOND function. For example, you want to get time value from a date and time value in Cell B1, you can write down the below formula.
Step 1: Type this formula into a blank cell C1 and press Enter key.
Step 2: Then you need to right click on the Cell C1, and select Format Cell from the pop-up menu list. The Format Cells dialog will open.
Step 3: switch to Number tab, and click Custom from the Category list. And select one type as: h:mm:ss. Click OK button.
#4 let’s see the result.
6. Extract Hour only from Date and Time
If you want to extract hour only, you just need to use the HOUR function. Like this:
If you want to extract minute only from a date and time value, you just need to use the MINUTE function. Like this:
If you want to extract second only from a date and time value, you just need to use the SECOND function. Like this:
7. Split Date and Time in Excel
If you want to split a date and time value into separate date and time values in Microsoft Excel, and you can use the above TEXT formula to Extract Date portion from date and time value.
Then you can use the below Text formula to extract the time portion of the date and time value:
Alternatively, you can also use the INT function to extract the date portion of the date and time value, enter the following formula in a new cell:
Enter the following formula in another cell to extract the time portion:
These formulas will return the date and time portions of the date and time value as serial numbers, which can be formatted as dates and times using the “Number Format” option in the “Home” tab of the Excel ribbon.
8. Convert Unix Timestamp to a Date in Excel
If you wish to convert a Unix timestamp to a date in Microsoft Excel, you can use the following TEXT formula:
In this formula, “
A1” represents the cell that contains the Unix timestamp. The Unix timestamp is divided by
86400 to convert it to the number of days since January 1, 1970. The result is then added to the date “1/1/1970” to give the date and time corresponding to the Unix timestamp. The “TEXT()” function is used to format the result as a date and time in the “
MM/DD/YYYY HH:MM:SS” format.
Note that the Unix timestamp is typically stored as an integer value representing the number of seconds since January 1, 1970, so you may need to divide the value in the cell by 86400 to convert it to a number of days.
9. If function with dates
The IF function in Microsoft Excel can be used with dates to perform conditional tests based on the values of dates. Here’s the general syntax for using the IF function with dates:
=IF(condition, [value_if_true], [value_if_false])
In this syntax, “
condition” is the logical test that you want to perform,
[value_if_true] is the value that will be returned if the condition is true, and
[value_if_false] is the value that will be returned if the condition is false.
Here’s an example of using the IF function with dates:
=IF(A1>B1, "A1 is later", "B1 is later")
In this example, the condition “
A1>B1” checks if the date in cell A1 is later than the date in cell B1. If the condition is true, the result will be “
A1 is later“, and if the condition is false, the result will be “
B1 is later“.
Note: When working with dates in Excel, it’s important to ensure that the dates are stored as dates and not as text. You can format a cell as a date by selecting it, right-clicking, selecting “Format Cells“, and then selecting the “Date” category under “Number“. From the available date formats, select the one you want to use and click “OK“.
10. Time Calculations in Excel
You can perform various calculations with times to get the result in terms of hours, minutes, or seconds. Here are a few examples of time calculations in Excel:
Add two times:
In this example, the two times in cells A1 and B1 are added together to give the result in the same time format.
Subtract one time from another:
In this example, the time in cell B1 is subtracted from the time in cell A1 to give the result in terms of a time.
Calculate the difference between two times in hours:
In this example, the difference between the two times is calculated in terms of hours by multiplying the result of the subtraction by 24.
Calculate the difference between two times in minutes:
In this example, the difference between the two times is calculated in terms of minutes by multiplying the result of the subtraction by 1440 (24 hours * 60 minutes).
In conclusion, extracting dates or times from datetime values in Microsoft Excel is very useful for data analysis and manipulation. Whether you need to separate dates and times for the purpose of sorting or calculating, or just to display the information in a different format, there are several ways to achieve it. Excel offers a range of options for extracting date or time information from datetime values.
12. Related Functions
- Excel TIME function
The Excel TIME function returns a date in serial number format for a particular time (the hour, minute and second).The syntax of the TIME function is as below:= TIME(hour, minute, second)…
- Excel HOUR Function
The Excel HOUR function returns the hour of a time value. Or returns an integer value that represent the hour component of a given time. The syntax of the HOUR function is as below:=HOUR (serial_number) …
- Excel MINUTE Function
The Excel MINUTE function returns the minutes of a time value. And the minutes is an integer number from 0 to 59. The syntax of the MINUTE function is as below:=MINUTE (serial_number)…
- Excel SECOND Function
The Excel SECOND function returns the seconds of a time value. Or returns an integer value that represent the second component of a given excel time. And the return value is between 0-59.The syntax of the SECOND function is as below:=SECOND (serial_number)…
CommentsSo empty here ... leave a comment!