Pages

Thursday 30 August 2012

Struggling to get a date? It's all in the set up....


So, hands up - who has been set up on a blind date by mutual "friends"? And how did that go for you? Disastrous? Embarrassing? Live happily ever after?

Going on the film versions, blind dates never work out that well. Because everyone has a different idea of what an 'ideal date' is. And two people, although they may seem to want the same thing, will have different preset ideas of what that 'thing' is. I think it is safe to say that in general, blind dates should be approached with as much care as you would use when trying to tackle a rabid tiger. Who has a sore tooth.

The same goes for Excel (not the tackling the tiger bit). Two people will have a different approach to a problem in Excel, because they have different preset ideas, or ways of working. As I keep on repeating, there is always more than one way to find a solution in Excel. A perfect example landed in my email box this week. In my newsletter last week, I pointed out that I was kinda running out of ideas for this blog.

(Side note - please note this point and feel free to comment below with topics you would like covered or problems you would like solved....)

Anyway, I got a lovely email from Mr B, who provided me with a variety of solutions on how to calculate the difference, in hours, between two dates and times. Now, working with dates and times in Excel is tricky. I have already done a basic blog on this (click here for a reminder), but Mr B reminded me of a brilliantly handy formula - the DATEDIF function. What this formula does is calculate the difference between two dates, but for specific criteria. The best way to explain this is to show you. Take note of the letters in inverted commas in the formulae, that is what defines the result you get:



The last 3 need a bit of explanation. Days only simply looks at the 'day' part of the date and subtracts one from the other (so 16 - 2). It ignores the months and years. The same goes for month only (so 8-5 in our example). Dates, ignoring years, assumes both dates fall into the same year and just calculates the difference in days.

Note when using DATEDIF that your Start Date comes first in the formula, and must always be earlier than the End Date.

So, after that whirlwind tour of the DATEDIF function, lets look at what Mr B sent me. Solution 1:



Here Mr B uses the DATEDIF, HOUR and MINUTE functions to break down the difference into days, then minutes, and then takes the answer back up to hours. Go through it at leisure...

Solution 2:


Again, go through this at your leisure, but he has shortened the equation by using the IFERROR and  MOD functions, which in this case basically say, if the answer is negative, then subtract the answer from 1 to get a positive.

These are both good solutions, and my thanks again to Mr B for sending them on. Clearly though, I have a female brain, so immediately thought of a different solution. I would use formatting to get this right. Under custom formats for numbers, you can select the format dd/mm/yyyy  hh:mm. So go to Home, Format, Number, Custom and scroll down till you find this beauty.

Then, to get the date and time into one cell, you would add the 2 together. So in the example above, to get the first start date and start time combined into one cell, it is as simple as =B4+A4. Doing this, you can get the table below:



To get the difference in hours, simply use =C3-C2, and keep the result cells formatted as numbers.

So, like I said, different strokes for different folks, but it all comes to the same answer.

Job done, another dating issue solved....

If you're new to this blog, and would like a reminder every time a new blog is posted, why not sign up here?

Happy spreadsheeting, and remember to send on any queries!





7 comments:

  1. Hi Vicky,

    I've been on this blog before but forgot to bookmark it. I had to search on LinkedIn to find you when I forgot your details: http://www.linkedin.com/groupItem?view=&gid=840577&type=member&item=175213521&qid=d16df611-280e-4613-bba1-0f5c20afa046&trk=group_most_popular-0-b-ttl&goback=.gmp_840577

    Anyway, can you pls help me with the following: My comments keep changing size and a quick google tells me do the following:
    Right-click on the border of a comment and select "Format comment", "Properties" tab and then select "Don't move or size with cells"

    However I don't have a Properties tab - is this to do with the version of Excel I'm using?

    TIA, Bernard McNamee

    ReplyDelete
  2. Hi Bernard

    Glad you tracked me down:-). You didn't mention what version of Excel you are using. Even in Excel 2003, you should get the Properties tab. I will run through the steps again, just to be sure:
    Right click on the side of your comment, and go to Format Comment on the dropdown list. This will open up a box with a number of tabs. The Properties tab should be at the back in the middle.

    If you are using an earlier version of Excel than 2003, then I can only suggest you upgrade!

    If you still don't come right, email through Linked In
    Thanks,
    Vicky

    ReplyDelete
  3. Hi Vicky,

    thanks for your reply. I'm using Excel 2010. Any ideas?

    Rgds, Bernard.

    BTW, should I expect to be notified when their is a response to my comment?

    ReplyDelete
  4. Maybe, auto-notification is only when I have signed in through Google or some other method?

    ReplyDelete
  5. Hi Vicky,

    I thought maybe it might be that all my excel files are saved as 'excel 97-2003 workbooks'. I tried saving as an xlsx file and tested but nothing different.

    Oh well, it's not a biggie!

    However, I do wish you could help me with this one: I do a lot of copying and pasting cells with formulae (eg =A1+B32) and I want the pasted formula to change to as follows: =A2+B32, =A3+B32, A4+B32, etc. Is there anyway that I can make this happen without going back to the formula an editing when it pastes as: =A2+B33, =A3+B34, A4+B35, etc.?

    Thank you, Bernard.

    ReplyDelete
  6. Hi Bernard
    Re your comment problem, maybe send me an email through linked in with the attachment and I can look at it for you.
    Re your formula problem - if you want to keep your formulas looking at cell B32, when you write the formula, "lock" B32 in place by placing a $ sign in front if it, like so: $B$32. If you want to keep the column locked, but move your formula down for each row, then you just put a $ before the B ($B32). In the same way, if you want to keep the row number the same, but drag across the columns, put the $ infront of the row number. (B$32).

    a shortcut for this is F4.

    Hope this helps!

    ReplyDelete
  7. Great stuff - that cell 'locking' will save me a lot of time!

    Yes, I'll send you a sample attachment.

    Many thanks, Bernard.

    ReplyDelete

Like this? Or not? Would you like a specific topic covered? Leave a comment and let me know.....