Date with my sheet – 10 tips on using date / time in excel

Posted on August 26th, 2008 in Learn Excel , ideas - 12 comments

Calendar - date with my sheet - 10 tips on using date / time in excelExcel date time features are very handy and knowing them a little in depth can help you save a ton of time in your day to day spreadsheet chores. Let us prepare for your date with the sheet using these 10 handy tips.

Before jumping on to the tips, it helps to know how excel represents the date and time.

Microsoft Excel stores dates as sequential numbers … By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. Excel stores times as decimal fractions because time is considered a portion of a day. [Excel Help Text on Date / Time]

So you see, Date and Time are in fact numbers in Excel. Just enter a date in your excel sheet and format it as number to see its equivalent numeric value. Today is 25-Aug-2008 and excel represents it as 39685.

Now that you know the little secret behind date / time, lets move to the 10 tips.

1. Test whether a date is future or past

You can find whether a date is past or future or today using simple if formula like: =if(this_date=today(),"Today",if(this_date < today(),"Past","Future"))

today() is the spreadsheet function using which you can find today's date.

2. Find the number of days between two dates

Since dates are represented as sequential numbers in excel, in order to find out how many days are between any given 2 dates, just subtract one from another. For eg. you can use =today()-datevalue("08/15/1947") to find that it is 22,291 days since India's independence (August 15, 1947).

3. Formatting dates

Date Time custom cell formats in Microsoft excel how toHaving date / time in the sheet is not enough if you can not make it look like the way you want. For eg. you may want to show date as "Monday - August 25, 2008". You can use cell formatting to do this. Just select the cell with date and hit ctrl+1 and in the "Number" tab select "Custom" as category and mention "dddd mmm dd, yyy" as format string.

Try these other date formats as well. Learn more about custom cell formatting.

4. Auto-filling only weekdays

Fill weekdays only excel

We all know that in order to fill a series of dates in excel sheet, you just need to enter first few dates and then select the range and drag to auto fill the selection with rest of the dates. But what if you need to fill only weekdays?

You can do that easily with Auto fill option - "weekdays only" as shown on the right. learn more.

5. Find out the day of week from a given date

Finding whether a day is weekend or weekday is useful if you are making project plans or resource allocation sheets. You can do this by simply using weekday() function. For eg. =weekday("08/25/2008") would return 2 (Excel, by default starts the week at Sunday, hence Monday is indicated as 2).

If you would like to start the week with Monday like most of us do, use =weekday("08/25/2008",2).

6. Highlight weekends using conditional formatting

Often when you are making project plans or reports, it helps if the weekends or after office hours can be grayed out. You can do this easily with conditional formatting as shown below:

highlight-weekends-in-excel-sheet-dates

In order to do this, we can test whether a given a day is weekend or not in conditional formatting by =WEEKDAY(this_date,2)>5 as weekday() returns 6 and 7 for Saturday and Sunday.

You can use similar logic to highlight after office hours (before 9AM or after 5PM) for time values. Learn these 5 tips to master conditional formatting.

7. Adding / Subtracting dates

Since Excel dates are nothing but numbers, you can find out the difference between two given dates by just subtracting one from another. For eg. ="09/20/2008"-"08/25/2008" will return 26

In order to add n number of days to a given date, you can just add that number to given date. For eg. ="08/25/2008"+26 will return 09/20/2008

8. Ensuring a valid date or time is entered in a cell

Data validation to ensure only dates are entered in an excel cellWhen sharing your sheets with others to enter some data, it may be useful if you can restrict them to enter only valid date values in cells that require date value. You can do that using cell data validation feature in excel. Just select the cell to which you want to apply date / time validation, goto menu > data > validation and set type as "Date" or "Time" and specify criteria.

For example, you can specify criteria like the one on left to ensure that date entered is at least 18 years before 1/1/2008. What more, using message option of data validation settings you can even show messages like this:

spreadsheet-date-time-validation

9. Insert today's date, current time using key board shortcuts

Just go to the cell where you want to insert date and press ctrl+;

To get current time, use ctrl+shift+; ( thus ctrl+: )

Btw, if you are planning to get today's date or current time using formulas, you can use today() and now(). Also learn these 11 very useful excel keyboard shortcuts.

10. Filling every 2nd / 3rd day

Often when you are entering dates in to the spreadsheet, it may be required to just enter every second or third day only. You can do this by changing the step value of auto-fill criteria (the default step value is 1).date-fill-alternatives

  • Enter the start date in first cell.
  • Select a range of cells in which you would like to fill rest of cells.
  • Go to Menu > Edit > Fill > Series
  • In the dialog, mention step criteria as 2 or 3 as shown aside.

That is all, with these 10 tips I hope I made your date with that spreadsheet is made little exciting.

Like this? Also read Master copy - paste with these 17 paste tricks, 6 things you dont know about excel if() functions, 15 fun things you can do with excel

| More
Subscribe for PHD Email updates and get a free excel e-book with 95 tips & tricks

Comments
Vijay Sharma February 23, 2009

Hi Chandoo,

Since this article was for Dates, below are 2 easy ones to calculate the Start and End of Month. (without using the EOMONTH formula as available in Analysis Toolpak).

In Cell A1, put any date
then in the cell where you would want the Start of Month put the below formula
1. Start of the Month
=DATE(YEAR(A1),MONTH(A1),1)

2. End of Month
=DATE(YEAR(A1),MONTH(A1)+1,0)

Hope this would help a lot who were dependant of EOMONTH..

cheers
~Vijay

Chandoo February 25, 2009

@Vijay: That is an awesome tip. Thank you so much for sharing it with all of us.

David B July 8, 2009

I run a trolley tour business and need to set up a data base to track tickets sold by mutable vendors (from store, on the street ,etc)and by class ( adult, senior,child and discounts ) can you help or direct me to one that could?

Glenn July 10, 2009

I know how to write macro’s for excel, but I have 1 issue that I cant figure out and would appreciate some help.
I want to key a range of dates, (7/1/09-7/12/09) then write a macro to go find the info for that range and bring it back to my spread sheet.

Thanks for any help….

Chandoo July 15, 2009

@Glenn: you can try a user defined function if the information you want to gather can be derived only from the 2 dates entered. You can write a macro, if you need to refer to other ranges in the workbook to gather the info based on the dates entered. I am not sure what you meant by “go find the info for that range”. May be if you tell what you are trying to find, I can suggest the approach for writing a macro…

sekhar October 14, 2009

talking about dates, therz a formula that i use very frequently to calculate the difference between two dates.
its not documented in 2007 though

=DATEDIF(START_DATE,END_DATE,”Y”) – gives you the years
=DATEDIF(START_DATE,END_DATE,”YM”) – remaining months
=DATEDIF(START_DATE,END_DATE,”MD”) – remaining days

im sure you’ll know this. wonder why it isnt documented. works fine with 2003 and 2007

RSS feed for comments on this post. TrackBack URI

Leave a comment

   Name (required)

   E-mail (required, never displayed)

   URL


If you have a question, please ask in the forums

Recommended Excel, Charting, VBA books