+ Reply to Thread
Results 1 to 6 of 6

Date error: 29/2/2023 shows Wed 01/03/2023

  1. #1
    Forum Contributor
    Join Date
    08-12-2010
    Location
    Excel World
    MS-Off Ver
    Excel 2013, 2019 & O365
    Posts
    214

    Date error: 29/2/2023 shows Wed 01/03/2023

    Hi All,

    I have 3 textboxes for date inputs for DD, MM and YYYY.
    (FYI, I cannot use any addin or ddl due to company policy, so I had to create add-in and ddl free date input in the UserForm.)

    Issue:
    If user puts 29/02/2023. the result shows me incorrect output as Wed 01/03/2023.

    Please Login or Register  to view this content.
    Can someone please let me know that how to avoid this date issue. I want that if user puts incorrect date then this formula should not display the dayname on a target label "Format(DateSerial(TextBoxYY.Text,TextBoxMM.Text,TextBoxDD.Text), "DDD")"
    Last edited by SunOffice; 05-26-2023 at 07:43 AM.
    Excelforum is Completely Awesome! True learning with Live Examples & Best Techniques!!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Date error: 29/2/2023 shows Wed 01/03/2023

    Why do you think that's wrong? 2023 doesn't have 29 days in February, so Excel calculates the correct date.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Date error: 29/2/2023 shows Wed 01/03/2023

    You would need to compare the month of the date calculated to the month in the text box.

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Date error: 29/2/2023 shows Wed 01/03/2023

    Some thing like this:
    PHP Code: 
    if month(DateSerial(TextBoxYY.Text,TextBoxMM.Text,TextBoxDD.Text)) <> TextBoxMM.Text then
         Msgbox 
    "wrong day - month"
         
    exit sub
    End 
    if 
    Quang PT

  5. #5
    Forum Contributor
    Join Date
    08-12-2010
    Location
    Excel World
    MS-Off Ver
    Excel 2013, 2019 & O365
    Posts
    214

    Re: Date error: 29/2/2023 shows Wed 01/03/2023

    Thank you @bebo021999 for the logic with code!
    Thank you @TMS for sharing thoughts/idea!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Date error: 29/2/2023 shows Wed 01/03/2023

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 04-20-2023, 11:29 PM
  2. Replies: 5
    Last Post: 03-09-2023, 03:29 AM
  3. Need Formula to Convert this Date Format 2023.02.28 to this 28-Feb-2023
    By gr445854 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-11-2023, 07:04 PM
  4. Replies: 1
    Last Post: 02-03-2023, 04:54 PM
  5. Run-Time Error 2023
    By SKINRIP in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2022, 09:52 AM
  6. [SOLVED] Error 2023: How to identify cell in For Each Loop?
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-12-2018, 12:21 AM
  7. [SOLVED] Error 2023 - triggered by variable - Cant find mistake
    By Taktiker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2012, 09:11 AM

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.6.0 RC 1