Format numbers as dates or times
Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 More…Less
When you type a date or time in a cell, it appears in a default date and time format. This default format is based on the regional date and time settings that are specified in Control Panel, and changes when you adjust those settings in Control Panel. You can display numbers in several other date and time formats, most of which are not affected by Control Panel settings.
In this article
-
Display numbers as dates or times
-
Create a custom date or time format
-
Tips for displaying dates or times
Display numbers as dates or times
You can format dates and times as you type. For example, if you type 2/2 in a cell, Excel automatically interprets this as a date and displays 2-Feb in the cell. If this isn’t what you want—for example, if you would rather show February 2, 2009 or 2/2/09 in the cell—you can choose a different date format in the Format Cells dialog box, as explained in the following procedure. Similarly, if you type 9:30 a or 9:30 p in a cell, Excel will interpret this as a time and display 9:30 AM or 9:30 PM. Again, you can customize the way the time appears in the Format Cells dialog box.
-
On the Home tab, in the Number group, click the Dialog Box Launcher next to Number.
You can also press CTRL+1 to open the Format Cells dialog box.
-
In the Category list, click Date or Time.
-
In the Type list, click the date or time format that you want to use.
Note: Date and time formats that begin with an asterisk (*) respond to changes in regional date and time settings that are specified in Control Panel. Formats without an asterisk are not affected by Control Panel settings.
-
To display dates and times in the format of other languages, click the language setting that you want in the Locale (location) box.
The number in the active cell of the selection on the worksheet appears in the Sample box so that you can preview the number formatting options that you selected.
Top of Page
Create a custom date or time format
-
On the Home tab, click the Dialog Box Launcher next to Number.
You can also press CTRL+1 to open the Format Cells dialog box.
-
In the Category box, click Date or Time, and then choose the number format that is closest in style to the one you want to create. (When creating custom number formats, it’s easier to start from an existing format than it is to start from scratch.)
-
In the Category box, click Custom. In the Type box, you should see the format code matching the date or time format you selected in the step 3. The built-in date or time format can’t be changed or deleted, so don’t worry about overwriting it.
-
In the Type box, make the necessary changes to the format. You can use any of the codes in the following tables:
Days, months, and years
To display |
Use this code |
---|---|
Months as 1–12 |
m |
Months as 01–12 |
mm |
Months as Jan–Dec |
mmm |
Months as January–December |
mmmm |
Months as the first letter of the month |
mmmmm |
Days as 1–31 |
d |
Days as 01–31 |
dd |
Days as Sun–Sat |
ddd |
Days as Sunday–Saturday |
dddd |
Years as 00–99 |
yy |
Years as 1900–9999 |
yyyy |
If you use «m» immediately after the «h» or «hh» code or immediately before the «ss» code, Excel displays minutes instead of the month.
Hours, minutes, and seconds
To display |
Use this code |
---|---|
Hours as 0–23 |
h |
Hours as 00–23 |
hh |
Minutes as 0–59 |
m |
Minutes as 00–59 |
mm |
Seconds as 0–59 |
s |
Seconds as 00–59 |
ss |
Hours as 4 AM |
h AM/PM |
Time as 4:36 PM |
h:mm AM/PM |
Time as 4:36:03 P |
h:mm:ss A/P |
Elapsed time in hours; for example, 25.02 |
[h]:mm |
Elapsed time in minutes; for example, 63:46 |
[mm]:ss |
Elapsed time in seconds |
[ss] |
Fractions of a second |
h:mm:ss.00 |
AM and PM If the format contains an AM or PM, the hour is based on the 12-hour clock, where «AM» or «A» indicates times from midnight until noon and «PM» or «P» indicates times from noon until midnight. Otherwise, the hour is based on the 24-hour clock. The «m» or «mm» code must appear immediately after the «h» or «hh» code or immediately before the «ss» code; otherwise, Excel displays the month instead of minutes.
Creating custom number formats can be tricky if you haven’t done it before. For more information about how to create custom number formats, see Create or delete a custom number format.
Top of Page
Tips for displaying dates or times
-
To quickly use the default date or time format, click the cell that contains the date or time, and then press CTRL+SHIFT+# or CTRL+SHIFT+@.
-
If a cell displays ##### after you apply date or time formatting to it, the cell probably isn’t wide enough to display the data. To expand the column width, double-click the right boundary of the column containing the cells. This automatically resizes the column to fit the number. You can also drag the right boundary until the columns are the size you want.
-
When you try to undo a date or time format by selecting General in the Category list, Excel displays a number code. When you enter a date or time again, Excel displays the default date or time format. To enter a specific date or time format, such as January 2010, you can format it as text by selecting Text in the Category list.
-
To quickly enter the current date in your worksheet, select any empty cell, and then press CTRL+; (semicolon), and then press ENTER, if necessary. To insert a date that will update to the current date each time you reopen a worksheet or recalculate a formula, type =TODAY() in an empty cell, and then press ENTER.
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
Need more help?
Want more options?
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
So I’ve been battling with this issue all day.
Basically I have it now sorted and part of the solution was a code that Excel itself generated which is:
[$-en-AU]yyyy-mm-dd hh:mm
So, in the first instance,
- in a new spreadsheet, type your entry in as per usual, eg:
2026-01-31 10:00
- set the format of the cell to «custom» and use the above formula, ie
[$-en-AU]yyyy-mm-dd hh:mm
- Hit enter and Bob’s your uncle!
Then save it as a CSV file, then close it and re-open it to check Excel hasn’t changed the date format.
The weird thing is if it does work (and I’ve re-tried it a few times successfully), when you check the format of the cell you’ve created, it’s changed the format to «General».
But seriously who cares. As long as it works!!
You can then copy and paste the cell and use it wherever you want!!
I hope this solution works for you!!
Regards
Richard
Date and time in excel are treated a bit differently in excel than in other spreadsheets software. If you don’t know how Excel date and time work, you may face unnecessary errors.
So, in this article, we will learn everything about the date and time of Excel. We will learn, what are dates in excel, how to add time in excel, how to format date and time in excel, what are date and time functions in excel, how to do date and time calculations (adding, subtracting, multiplying etc. with dates and times).
What is Date and Time in Excel?
Many of you may already know that Excel dates and time are nothing but serial numbers. A date is a whole number and time is a fractional number. Dates in excel have different regional formatting. For example, in my system, it is mm/dd/YYYY (we will use this format throughout the article). You may be using the same date format or you could be using dd/mm/YYYY date format.
Date Formatting of Cell
There are multiple options available to format a date in Excel. Select a cell that may contain a date and press CTRL+1. This will open the Format Cells dialogue box. Here you can see two formatting options as Date and Time. In these categories, there are multiple date formattings available to suit your requirements.
Dates:
Dates in Excel are mare serial numbers starting from 1-Jan-1900. A day in excel is equal to 1. Hence 1-Jan-1900 is 1, 2-Jan-1900 is 2, and 1-Jan-2000 is 36526.
Fun Fact: 1900 was not a leap year but excel accepts 29-Feb-1900 as a valid date. It was a desperate glitch to compete Lotus 1-2-3 back in those days.
Shortcut to enter static today’s date in excel is CTRL+; (Semicolon).
To add or subtract a day from a date you just need to subtract or add that number of days to that date.
Time:
Excel by default follows the hh:mm format for time (0 to 23 format). The hours and minutes are separated by a colon without any spaces in between. You can change it to hh:mm AM/PM format. The AM/PM must have 1 space from the time value. To include seconds, you can add :ss to hh:mm (hh:mm:ss). Any other time format is invalid.
Time is always associated with a date. The date comes before the time value separated with a space from time. If you don’t mention a date before time, by default it takes the first date of excel (which is 1/1/1900). Time in excel is a fractional number. It is shown on the right side of the decimal.
Hours:
Since 1 day is equal to 1 in excel and 1 day consists of 24 hours, 1 hour is equal to 1/24 in excel. What does that mean? It means that if you want to add or subtract 1 hour to time, you need to add or subtract 1/24. See the image below.
you can say that 1 hour is equal to 0.041666667 (1/24).
Calculate hours between time in Excel
Minutes:
From the explanation of the hour in excel, you must have guessed that 1 Minute in excel is equal to 1/(24×60) (or 1/1440 or 0.000694444).
If you want to add a minute to an excel time, add 1/(24×60). See the image below. Sometimes you get the need to Calculate Minutes Between Dates & Time In Excel, you can read it here.
Seconds:
Yes, a second in Excel is equal to 1/(24x60x60). To add or subtract seconds from a time, you just need to do the same things as we did in minutes and hours.
Date and Time in one cell
Dates and times are linked together. A date is always associated with a valid date and time is always associated with a valid excel date. Even if you are not able to see one of them.
If you only enter a time in a cell, the date of that cell will 1-Jan-1900, even if you are not able to see it. If you format that cell as a date-time format, you can see the associated date. Similarly, if you don’t mention time with the date, by default 12:00 AM is attached. See the image below.
In the image above, we have time only in B3 and date only in B4. When we format these cells as mm/dd/yy hh:mm, we get both, time and date in both cells.
So, while doing date and time calculations in excel, keep this in check.
No Negative Time
As I told you the date and time in excel starts from 1-Jan-1900 12:00 AM. Any time before this is not a valid date in excel. If you subtract a value from a date that leads to before 1-Jan-1900 12:00, even one second, excel will produce ###### error. I have talked about it here and in Convert Date and Time from GMT to CST. It happens when we try to subtract something that leads to before 1 Jan-1900 12:00. Try it yourself. Write 12:00 PM and subtract 13 hours from it. see what you get.
Calculations with Dates and Time in Excel
Adding Days to a date:
Adding days to a date in excel is easy. To add a day to date just add 1 to it. See the image below.
You should not add two dates to get the future date, as it will sum up the serial numbers of those days and you may get a date far in the future.
Subtracting Days from Date:
If you want to get a backdate from a date a few days before, then just subtract that number of days from the date and you will get backdate. For example, if I want to know what date was before 56 days since TODAY then I would write this formula in the cell.
This will return us the date of 56 before the current date.
Note: Remember that you can not have a date before 1/Jan/1900 in excel. If you get ###### error, this could be the reason.
Days between two dates:
To calculate days between two dates we just need to subtract the start date from the end date. I have already done an article on this topic. Go and check it out here. You can also use the Excel DAYS Function to calculate days between a start date and end date.
Adding Times:
There’s been a lot of queries on how to add time to excel as many people get confusing results when they do it. There are two types of addition in times. One is adding time to another time. In this case, both times are formatted as hh:mm time format. In this case, you can simply add these times.
The second case is when you don’t have additional time in time format. You just have numbers of hours, minutes and seconds to add. In that case, you need to convert those numbers to their time equivalents. Note these points to add hours, minutes and seconds to a date/time.
- To add N hours to an X time use formula =X+(N/24) (As 1=24 hours)
- To Add N minutes to X time use formula = X+(N/(24*60))
- To Add N Second to X time use formula = X+(N/(24*60*60))
Subtracting Times
It’s the same as adding time, just make sure that you don’t end up with a negative time value when subtracting, because there is no such thing as a negative number in excel.
Note: When you add or subtract time in excel that exceeds 24 hours of difference, excel will roll to the next or previous date. For example, if you subtract 2 hours from 29-Jan-2019 1:00 AM then it will roll back to 28-Jan-2019 11:00 PM. If you subtract 2 hours from 1:00 AM (does not have the date mentioned), Excel will return ###### error. I have told the reason at the beginning of the article.
Adding Months to a Date:
You can’t just add multiples of 30 to add months to date as different months have a different number of days. You need to be careful while adding months to Date. To add months to a date in excel, we use EDATE function of excel. Here I have a separate article on adding months to a date in different scenarios.
Adding years to date:
Just like adding months to a date, it is not straightforward to add years to date. We need to use YEAR, MONTH, DAY function to add years to date. You can read about adding years to date here.
If you want to calculate years between dates then you can use this.
Excel Date and Time Handling Functions:
Since date and time are special in Excel, Excel provides special functions to handle them. Here I am mentioning a few of them.
- TODAY(): This function returns today’s date dynamically.
- DAY(): Returns Day of the month (returns number 1 to 31).
- DAYS(): Used to count the number of days between two dates.
- MONTH(): Used to get the month of the date (returns number 1 to 12).
- YEAR(): Returns year of the date.
- WEEKNUM(): Returns the weekly number of a date, in a year.
- WEEKDAY(): Returns the day number in a week (1 to 7) of the supplied date.
- WORKDAY(): Used to calculate working days.
- TIMEVALUE(): Used to extract Time value (serial number) from a text formatted date and time.
- DATEVALUE(): Used to extract date value (serial number) from a text formatted date and time.
These are some of the most useful data and time functions in excel. There are plenty more date and time functions. You can check them out here.
Date and Time Calculations
If I explain all of them here, this article will get too long. I have divided these time calculation techniques in excel into separate articles. Here I am mentioning them. You can click on them to read.
- Calculate days, months and years
- Calculate age from date of birth
- Multiplying time values and numbers.
- Get Month name from Date in Excel
- Get day name from Date in Excel
- How to get a quarter of the year from date
- How to Add Business Days in Excel
- Insert Date Time Stamp with VBA
So yeah guys, this is all about the date and time in excel you need to know about. I hope this article was useful to you. If you have any queries or suggestions, write them down in the comments section below.
The objective of this post is to teach you how Excel handles date and time and provide you with all the tools you will need.
It’s designed to be read in conjunction with the accompanying Excel file, which you can download below.
Download the Files
Enter your email address below to download the comprehensive Excel workbook and PDF.
By submitting your email address you agree that we can email you our Excel newsletter.
Regional Settings
When reading this post keep in mind that my regional settings format dates as dd/mm/yyyy and so the screenshots throughout this post are in this format. However, if you open the accompanying Excel file you may see some dates have switched to match your regional settings, which may be different to mine e.g. mm/dd/yyyy.
Dates and times with a format that begins with an asterisk (*) automatically update based on your PC’s regional settings. You can see an example in the Format Cells dialog box below:
Ok, let’s crack on.
Excel Date and Time 101
Excel stores dates and time as a number known as the date serial number, or date-time serial number.
When you look at a date in Excel it’s actually a regular number that has been formatted to look like a date. If you change the cell format to ‘General’ you’ll see the underlying date serial number.
The integer portion of the date serial number represents the day, and the decimal portion is the time. Dates start from 1st January 1900 i.e. 1/1/1900 has a date serial number of 1.
Caution! Excel dates after 28th February 1900 are actually one day out. Excel behaves as though the date 29th February 1900 existed, which it didn’t.
Microsoft intentionally included this bug in Excel so that it would remain compatible with the spreadsheet program that had the majority market share at the time; Lotus 1-2-3.
Lotus 1-2-3 was incorrectly programmed as though 1900 was a leap year. This isn’t a problem as long as all your dates are later than 1st March 1900.
Excel gives each date a numeric value starting at 1st January 1900. 1st January 1900 has a numeric value of 1, the 2nd January 1900 has a numeric value of 2 and so on. These are called ‘date serial numbers’, and they enable us to do math calculations and use dates in formulas.
The Date Serial Number column displays the Date column values in their date serial number equivalent.
e.g. 1/1/2017 has a date serial number of 42736. i.e. 1st January 2017 is 42,736 days since 31st December 1899.
Tip: format the date serial number column as a Date and you’ll see they look the same as the Date column values.
Time
Times also use a serial number format and are represented as decimal fractions.
Hours: since 24 hours = 1 day, we can infer that 24 hours has a time serial number of 1, which can be formatted as time to display 24:00 or 12:00 AM or 0:00. Whereas 12 hours or the time 12:00 has a value of 0.50 because it is half of 24 hours or half of a day, and 1 hour is 0.41666′ because it’s 1/24 of a day.
Minutes: since 1 hour is 1/24 of a day, and 1 minute is 1/60 of an hour, we can also say that 1 minute is 1/1440 of a day, or its time serial number is 0.00069444′
Seconds: since a second is 1/60 of a minute, which is 1/60 of an hour, which is 1/24 of a day. We can also say one second is 1/86400 of a day or in time serial number form it’s 0.0000115740740740741…
Date & Time Together
Now that we know how dates and times are stored we can put them together — ddddd.tttttt
For example, the date and time of 1st January 2012 10:00:00 AM has a date-time serial value of 40909.4166666667
40909 being the serial value representing the date 1st January 2012, and .4166666667 being the decimal value for the time 10:00 AM and 00 seconds.
More examples below.
Entering Dates & Times in Excel
Entering Dates
You can type in various configurations of a date and Excel will automatically recognise it as a date and upon pressing ENTER it will convert it to a date serial number and apply a date format on the cell.
For example, try typing (or even copy and paste) the following dates into an empty cell:
1-1-2009 |
1-1-09 |
1/1/2009 |
1/1/09 |
1-Jan-09 |
1-Jan 09 |
1-Jan-2009 |
1 Jan 09 |
1/1 |
You can see in the table above that entering numbers that look like dates and are separated by a forward slash or hyphen will be recognised as a date. Even typing in a date with the month name gets converted to a date.
However, dates separated with a period like this 1.1.2009, or with spaces between numbers like this 01 01 2009, will end up as text, not a date. Gotta have some limits!
Tip: Dates that display ##### in a cell usually indicate that the column is simply not wide enough to display it.
However, if you make the cell really wide and it still displays ##### then this indicates that the date is a negative value and Excel can’t display negative dates.
Entering Dates with Two Digit Years
When you enter a date with two digits for the year e.g. 1/1/09, Excel has to decide if you mean 2009 or 1909.
It goes by the rule that dates with years 29 or before, are treated as 20xx and dates with the year 30 or older are treated as 19xx. See examples below.
Tip: You can enter the day and month portions of a date and Excel will insert the year based on your computer’s clock. Nice to know for data entry.
Entering Time
When you enter time you must follow a strict format of at least h:mm. i.e. the hour and minutes are separated by a colon with no spaces either side. Entering the h:mm components will result in a time formatted in military time e.g. 2:00 PM is 14:00 in military time.
If you enter a time that includes a seconds component e.g. 3:15:40, Excel will automatically format the cell in h:mm:ss.
If you want the time to be formatted with AM/PM you can simply enter a space after the time and then type AM or PM, or apply the number format to the cell later. Here are some examples:
Entering Dates & Time Together
Now that we know how to enter dates and time separately we can put them together to enter a date and time in the same cell.
You can even enter time then date and Excel will fix the order for you.
You’ll find that even if you enter AM/PM, that Excel will convert it to military time by default. You can override this with a custom number format. More on that later.
Simple Date & Time Math
Now that we understand that Excel stores dates and time as serial numbers, you’ll see how logical it is to perform math operations on these values. We’ll look at some simple examples here and tackle the more complex scenarios later when we look at Date and Time Functions.
Adding/Subtracting Days from Dates
Tip: you can also add/subtract the days directly in the formula e.g. =B10+10 or =B11-5 Although, it’s better to place the values you’re adjusting by in their own cell or a named range.
Subtracting Dates from one another
Tip: format the cell to General or Number to see the number of days between two dates.
Note: the ‘result’ is exclusive of the start day i.e. it assumes the start day is at the end of that day.
Adding Times to one another
The time being added is input as a time serial number. Notice there are no negative times in the table below. Remember we can’t display negative times. Instead we need to use the math operator to tell Excel to subtract time. See examples below.
Note: Times that roll over to the next day result in a time-date serial number >= 1. Cell E28 actually contains a time-serial number of 1.08333′, but since the cell is formatted to display time formatted as h:mm:ss, only the time portion is visible.
If you want to show the cumulative time (like cell E29) then you need to surround the ‘h’ part of the time format in square brackets like so: [h]:mm:ss
Subtracting Time from Times
Notice the last result in the table below shows ######, this is because it results in a negative time and Excel can’t display that, but notice it can return a negative time serial number. More on how to solve this later.
Subtracting Times from one another
Again, here the last result shows ###### because it results in a negative time.
Excel Date and Time Shortcuts
‘Good to Know’ Stuff about Excel Date and Time
— Dates prior to 1st January 1900 are not recognised in Excel.
— A negative date will display in the cell as #######
— Times stored without a date effectively inherit the date 0 Jan 1900 i.e. the month is Jan and the year 1900 and the day is zero. Remember, there are no dates prior to 1/1/1900 from Excel’s perspective. This means that times stored without a date e.g. 0.50 for 12:00 PM is the equivalent of 0 Jan 1900 12:00 PM.
This is important because if you try to take 14 hours from 12 hours (without a date) you’ll get the dreaded ###### display in the cell, because negative dates and times cannot be displayed. We’ll cover workarounds for this later, but for now keep in mind that math on dates and time that result in negative date-time serial numbers cannot be formatted as a date.
Date Modes
— Excel actually has two date modes. The other mode is called 1904 Date System and is used for compatibility with Excel 2008 for Mac and earlier Mac versions. You can change the date system in the Advanced Options.
In the 1904 date system dates are calculated using 1st January 1904 as the starting point. The difference between the two date systems is 1,462 days. This means that the serial number of a date in the 1900 date system is always 1,462 days greater than the serial number of the same date in the 1904 date system. 1,462 days is equal to four years and one day (including one leap day).
Caution; the date setting you choose applies to all dates within the workbook. You can’t mix and match modes and you shouldn’t reference workbooks that use a different date system in formulas.
Bottom line; don’t use the 1904 date system unless absolutely necessary! Click here for more on date systems in Excel.
— Excel applies date number formats based on your system region settings. For example, my system is set to display dates in dd/mm/yyyy format, but if you’re in the U.S. your system is likely to format them as mm/dd/yyyy. Excel will automatically convert the format of date serial numbers to suit your system settings as long as it’s one of the default date formats and not a custom number format.
More Excel Date and Time Tips
This post is just the beginning, the next steps in mastering Excel Date and Time are below:
- Every Excel Date and Time Function explained
- Formatting Date and Time in Excel
- Common Date and Time Calculations
Tip: Avoid waiting, download the workbook and get the above topics now.
Enter your email address below to download the comprehensive Excel workbook and PDF.
By submitting your email address you agree that we can email you our Excel newsletter.
MS Excel offers many possibilities how display date and time. The custom format can be set in the Format Cells… menu. Do the right-click and select Format Cells… .
In the item Number select Custom.
Into the field Type: write the date/time codes.
Date format codes
Day
d – day number (0–31)
dd – day number (01–31) / two digits
ddd – day as an abbreviation (mon–sun)
dddd –day name (monday–sunday)
Month
m – month number (1–12)
mm – month number (01–12) / two digits
mmm –month as an abbreviation (Jan–Dec)
mmmm – month name (January–December)
mmmmm – the first letter of month name
Year
yy – year number (00–99) / two digits
yyyy – year number (1900–9999) / four digits
Examples of custom date format
Let’s have the date 3.1.2012
Code | Date |
dd/mm/yyyy | 03/01/2012 |
mm/dd/yyyy | 01/03/2012 |
d-m-yyyy | 3-1-2012 |
dd-mm-yy | 03-01-12 |
dddd | Tuesday |
dd. mm. yyyy dddd | 03. 01. 2012 Tuesday |
mmmm | January |
d. mmmm yyyy | 3. January 2012 |
mmmm dd, yyyy | January 03, 2012 |
dddd, mmmm dd yyyy | Tuesday, January 03 2012 |
ddmmyy | 030112 |
dd. “text” | 03. text |
Time format codes
h – hour number (0–23)
hh – hour number (00–23) / two digits
m – minute number (0–59)
mm – minute number (00–59)
s – second number (0–59)
ss – second number (00–59)
AM/PM or am/pm – Convert from 24 Hour to 12 Hour Time
[h] – elapsed time in hours (can be greater than 24, e.g. for sports results)
[mm] – elapsed time in minutes (can be greater than 60, e.g. for sports results)
[ss] – elapsed time in minutes (can be greater than 60, e.g. for sports results)
h:mm:ss.00 – fractions of seconds
Examples of custom time format
Let’s have the time 6:25:31
Code | Time |
hh.mm | 06.25 |
hhmm | 0625 |
h:mm:ss AM/PM | 6:25:31 am |
hh “hours and” mm “minutes” | 06 hours and 25 minutes |
[m] | 385 (the number of minutes since 00:00:00) |
[s] | 23131 (the number of seconds since 00:00:00) |
Examples of custom date/time format
Date and time formats can be combined. Notice that month and minute have the same code. Immediately after the hours writes Excel the minutes.
Default date/time: 4.11.2010 6:25
Code | Date/Time |
hh:mm dd/mm/yyyy | 06:25 04/11/2012 |
dddd hh:mm | Thursday 06:25 |
Note: In other language versions of Excel can be format codes different.
To generate a DateTime sequence in Excel, we can use the SEQUENCE function with the DATE function. We will see how to do that.
But if you want the sequence of date and time separately, we may also require the MOD, INT, and TIME functions.
The formulas below apply to Excel 365 as it uses the SPILL feature and SEQUENCE function, which may not be available in other versions.
You may already know how to generate a sequence of dates in Excel. If not, here it is.
Excel Formula # 1:
=DATE(2022,1,1)+SEQUENCE(10,1,0)
Generic Version: =start_date+SEQUENCE(number_of_days,1,0)
The above Excel formula in cell A2 will generate the dates from 01-Jan-2022 to 10-Jan-2022, i.e., ten days, in cell range A2:A11.
You may require to format A2:A11 to Date. How?
You can do that in Excel 365 by selecting A2:A11 and clicking Date (Short Date or Long Date) in the number format box on the Home tab > Number group.
What about a Time sequence?
Excel Formula # 2:
=TIME(0,0,0)+MOD(SEQUENCE(1*24,1,0)/24,1)
Generic Version: =start_time+MOD(SEQUENCE(number_of_days*24,1,0)/24,1)
The above formula in cell C2 will generate the time sequence from 00:00:00 hrs. to 23:00:00 hrs. in the range C2:C25. The time interval will be one hour.
Here also, you may require to format this range.
Here, instead of Long/Short Date, select Time in the format box on the Home tab Number group.
Combining the above two outputs won’t generate the sequence of DateTime in Excel?
Please take a look at columns A, C, and E.
We have ten dates in column A and the time sequence is only for one day (24 hours).
We must repeat each date from 01-Jan-2022 to 10-Jan-2022 twenty-four times and repeat the time sequence ten times.
That’s not a big issue in an Excel spreadsheet, though.
Instead of combining, we can use a single formula in cell E2.
I have the below formula to generate the DateTime sequence in Excel 365.
Excel Formula # 3:
=DATE(2022,1,1)+SEQUENCE(10*24,1,0)/24
Generic Version: =start_date+SEQUENCE(number_of_days*24,1,0)/24
This time we should format the range E2:E241 to dd-mm-yyyy hh:mm:ss
.
How to Format Date Value to DateTime in Excel?
- Select the range to format here E2:E241.
- Go to the Home tab Number group and click More Number Formats (inside the format box).
- Select Custom category and enter the above custom formatting under the Type field.
Extracting the Date and Time into Separate Columns from DateTime Sequence
Date:
Just wrap INT with the sequence part of the above formula # 3.
=DATE(2022,1,1)+INT(SEQUENCE(10*24,1,0)/24)
You may format the output to Short or Long Date.
Time:
To get the time parts separately, use formula # 2. But you should replace 1*24
with 10*24
.
=TIME(0,0,0)+MOD(SEQUENCE(10*24,1,0)/24,1)
You may format the output to Time.
Time Sequence with 30 or 15 Minutes Interval in Excel
In all the above examples, we were using 60 minutes (1-hour) intervals.
For example, take the C2 formula, i.e., formula # 2.
In that Excel formula, replace 24 with 48 to get a time sequence with 30 minutes intervals.
=TIME(0,0,0)+MOD(SEQUENCE(1*48,1,0)/48,1)
To get a time sequence with 15 minutes intervals, replace 24 with 96.
=TIME(0,0,0)+MOD(SEQUENCE(1*96,1,0)/96,1)
Does this apply to our DateTime sequence formula # 3 in cell E2?
Yep! The same changes are applicable there also.
Excel 365 Resources
- Sumif between Two Dates in Excel (How-To).
- Date Wise Running Total Array Formula in Excel.
- Array Formula to Combine Texts and Dates in Excel 365.
- Copying Rows Containing Dates in a Column in Excel 365.
- All Necessary Rules to Highlight Dates in Excel 365.
- Count By Date, Month, Year, Date Range in Excel 365 (Array Formula).
- Reverse Sequence in Excel 365 – Formula and Examples.
Sometimes you may have dates in one column and time values in another column and you want to combine these to get one single date and time value in a cell.
And if you’re thinking that you can do that by easily combining the two cells by using the concatenate formula or the & sign, you’ll find out that it doesn’t work.
I have tried to use the & sign to combine the cells that contain date and time, and the resulting value is not in the expected format.
In this tutorial, I will show you a couple of ways to quickly combine date and time values in Excel.
So let’s get started!
Combine Date and Time with a Simple Addition
Excel stores date and time values as numbers in the back end.
For example, 44197.375 in Excel represents 01-01-2021 09:00 AM
The integer part of the above number represents a date (which is 01 Jan 2021), and the decimal part of the number represents a time (which is 9 AM)
So, if you have dates in one column and time in another column, the easiest way to combine these and get the date and time in one single cell would be to simply add these two cells.
Suppose you have a data set as shown below and you want to combine the date and time in column C.
Below is the formula that will do that:
=A2+B2
All this formula to all the cells in the column to get the combined date and time values.
It automatically picks up the format from the cells and shows you the result that has the date portion and the time portion.
As I mentioned, dates and times are stored as numbers in Excel. The combined date and time that you see in the cells in column C are also decimal numbers in the back end.
In case you want to show that result in a different format, you can do that using the format cells dialog box (where you can specify the custom code to show the date and time in a specific way).
In most cases, Excel will take care of the formatting and you will see the date as well as the time as shown above. In case it doesn’t, you will have to change the cell formatting to show the combined date and time.
Combine Date and Time with a TEXT Function
Another quick way to combine date and time in Excel is by using the CONCAT formula with the TEXT function.
Suppose you have a dataset as shown below and you want to combine the date and time and get the result in column C.
Below is the formula that can do this:
=CONCAT(TEXT(A2,"dd-mm-yyy")," ",TEXT(B2,"hh:mm:ss"))
The TEXT function allows you to take any value as the input and show it in the specified format.
In our example, I have used two TEXT functions, the first one takes the date value and displays it as a date and the second one takes the time value and displays it as the time.
And since I want both of these in the same cell, I have used the CONCAT formula with space as the separator in between the date and time.
Since we have used the TEXT function to specify the format for the date and the time, it does not matter how the input values are displayed in the cell.
For example, even if I have the numerical values instead of the date and the time, this formula would still give me the right result.
Another big benefit of using the text function is that you can combine other text strings with the result of this formula.
To give you an example, let’s say I don’t want just the date and the time, I want the result in the following format – Date: 01 Jan 2021, Time: 09:00 AM
To do this, you can use the below formula:
=CONCAT("Date: "&TEXT(A2,"dd-mm-yyy"),", ","Time: "&TEXT(B2,"hh:mm:ss AM/PM"))
Since the result of the TEXT function is a text string, we can easily combine it with the other text strings using the ampersand operator (&) or CONCAT formula.
So these are two simple ways you can use to combine date and time in Excel.
I hope you found this tutorial useful.
Other Excel tutorials you may also like:
- Calculate Time in Excel (Time Difference, Hours Worked, Add/ Subtract)
- Convert Time to Decimal Number in Excel (Hours, Minutes, Seconds)
- How to Remove Time from Date/Timestamp in Excel
- How to Quickly Insert Date and Timestamp in Excel
- How to Change Date Format In Excel?
- How to Add Months to Date in Excel
- How to Compare Dates in Excel (Greater/Less Than, Mismatches)