+ Reply to Thread
Results 1 to 8 of 8

Thread: Date time validation - Excel turns h:mm into h:mm:ss

  1. #1
    Registered User
    Join Date
    08-08-2011
    Location
    Dublin, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Date time validation - Excel turns h:mm into h:mm:ss

    Hello!

    I'm currently tearing my hair out trying to figure out how to validate a cell where users input the date and time.

    I have a formula set up that calculates the time difference between two cells. It will only calculate properly if the date and time are entered as:
    [$-409]m/d/yy h:mm AM/PM;@
    This would all be great if the end users would actually follow directions and enter the data as instructed. However, when I add validation to the columns with the dates & times, it fails because when users enter, for example, 7/15/11 8:03 AM, Excel automatically turns it into 7/15/11 8:03:00 AM, thus making the entry invalid.

    Is there any way to stop Excel from automatically appending the seconds on to the time? Thanks in advance for your help!

    Using Excel 2007, if that makes any difference.
    Last edited by werm; 08-08-2011 at 08:20 AM. Reason: Added Excel version.

  2. #2
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    10,056

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    As long as valid times are entered then the formatting shouldn't matter - formatting only affects the way the data is displayed - it shouldn't have an impact on any calculations, e.g. 12:45:00 will be treated the same as 12:45

    Which formula are you using for time difference - you should only have to subtract one from the other?
    Audere est facere

  3. #3
    Registered User
    Join Date
    08-08-2011
    Location
    Dublin, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    The formula goes a little something like this:
    =IF((OR(H142="N/A",I142="N/A",M142="Y")),"N/A",I142-H142)
    It's a hand-me-down spreadsheet, so I didn't write the formulas, I can just tell you what the formulas are...

  4. #4
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    10,056

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    OK, so with some conditions that's just a subtraction as I suggested. Why doesn't that work if seconds are displayed? It shouldn't make any difference......
    Audere est facere

  5. #5
    Registered User
    Join Date
    08-08-2011
    Location
    Dublin, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    The validation I'm using is
    Allow: Custom
    Formula: [$-409]m/d/yy h:mm AM/PM;@
    I'm assuming this is where the problem lies, because it's checking for h:mm, but Excel changes the input to h:mm:ss. Is there any way to tell the spreadsheet to stop appending the seconds?

  6. #6
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    10,056

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    I think you are confusing several different things here.....

    You said that your formula didn't work correctly if the seconds were displayed - I don't follow you, as previously stated the display won't affect the calculations......

    You say you are using data validation but what you have quoted would normally be used in number formatting rather than data validation.

    If you don't want seconds entered then try this

    Custom format cells as per your suggestion, i.e.

    [$-409]m/d/yy h:mm AM/PM;@

    [this simply stops display of seconds, it doesn't dictate whether there are seconds in the value]

    then use custom data validation like this:

    =SECOND(A1)=0

    [assuming you are entering data in A1 - change as required]

    That prevents user entering seconds other than zero
    Audere est facere

  7. #7
    Registered User
    Join Date
    08-08-2011
    Location
    Dublin, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    I'm sorry, I got it mixed up. The calculation works fine either way.
    I'm trying to prevent people from entering the date and time in different formats, like
    8/3/11 336pm
    which breaks the formula.

    So I have the validation set up like suggested, with
    [$-409]m/d/yy h:mm AM/PM;@
    , but whenever I try to enter the date & time in the exact format it's looking for, I get a validation error. Does that make more sense?

  8. #8
    Registered User
    Join Date
    08-08-2011
    Location
    Dublin, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Date time validation - Excel turns h:mm into h:mm:ss

    Here is an example spreadsheet, identical to what I'm working with if it helps at all.

    Maintenance Log.xlsx

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0