Office & Productivity Software forum

Question

Has anyone found a problem with date handling in Excel 2010

by not4prophet / August 22, 2014 2:01 AM PDT

I have generated dates for the first fourteen days of August to demonstrate the error. The dates are created using DateSerial function varying the day part; these are loaded into a combobox (and displayed via Msgbox to check); Msgbox displays the dates in dd/mm/yyyy format as expected but when the dates are displayed in the combobox they appear to be in mm/dd/yyyy format; selecting the first twelve entries I get the 8th of each month but selecting the last two entries I get the 13th or 14th of August! Needless to say, access to Microsoft has produced no one who can help as this is a coding problem or not to do with Office! I can supply demo code if required.

Thanks.

Discussion is locked
You are posting a reply to: Has anyone found a problem with date handling in Excel 2010
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Has anyone found a problem with date handling in Excel 2010
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.

All Answers

Collapse -
Answer
Can be true.
by R. Proffitt Forum moderator / August 22, 2014 2:12 AM PDT
Collapse -
Is there any hope?
by not4prophet / August 22, 2014 5:45 AM PDT
In reply to: Can be true.

I take it that there is no "fix" to this problem! Apart, that is, to coding my own handler, but I am wary that the results I use will be reliable. I used the following code with a blank worksheet and a userform with one combobox (called combobox1) to show the error.

Private Sub ComboBox1_Change()

MsgBox "ComboBox1.Value " & TypeName(ComboBox1.Value) & " " & ComboBox1.Value & vbCr & _
"ComboBox1.Text " & TypeName(ComboBox1.Text) & " " & ComboBox1.Text & vbCr & _
FormatDateTime(ComboBox1.Text, vbShortDate) & " " & FormatDateTime(ComboBox1.Text, vbLongDate) & " " & CStr(ComboBox1.Text)

Sheet1.Range("A" & Day(ComboBox1.Text)).Value = (ComboBox1.Text)

End Sub

Private Sub UserForm_Initialize()
Dim d1 As Date

For dd = 1 To 14
ComboBox1.AddItem DateSerial(2014, 8, dd)
MsgBox DateSerial(2014, 8, dd) & vbCr & CStr(DateSerial(2014, 8, dd))
Next dd

End Sub

Collapse -
Looking at your code
by Jimmy Greystone / August 22, 2014 12:07 PM PDT
In reply to: Is there any hope?

Looking at your code, I'm wondering what the point of the dateserial function is. You're hard coding the month and year, so why not just have something like

combobox1.additem dd & "/08/2014"

Why waste time on a function that isn't even working correctly when you're essentially feeding it the data you want anyway? A simple switch case routine could handle whether the month has 30 or 31 days (or 28 even 29). Nested for loops to handle the year and month or you could just use the end of the year as a convenient excuse to push a new update to the program. Tiny bit of job security.

Collapse -
Not so helpful....
by not4prophet / August 23, 2014 9:38 AM PDT
In reply to: Looking at your code

Thanks for the suggestion but if I had employed this method the simple demonstration code would not reflect the functionality of the original code which calculates new dates by varying the Year, Month and Day parts by varying amounts. Accuracy to the day is of import in the original code.

Collapse -
If you know
by Jimmy Greystone / August 23, 2014 11:13 AM PDT
In reply to: Not so helpful....

If you know you're consistently getting mm/dd/yyyy you could just break it up and reassemble it. Something like:

newdate = mid(4, 2, olddate) & "/" & left(2, olddate) & "/" & right(4, olddate)

My syntax might be somewhat off, but it should give you the basic idea. You know the format of the date you're getting, so you can break it into substrings and then reassemble it in the format you want. If you're not positive you're always going to have two digits you could probably break it into substrings based on the / character. It's a lot of work that only you will even know exists, but the alternative is you will just have to live with the fact that the function wasn't internationalized very well.

Collapse -
Have to go with no.
by R. Proffitt Forum moderator / August 23, 2014 1:29 AM PDT
In reply to: Is there any hope?

Unless you simplify it as noted by Jimmy G, all is working according to plan. That is, if regional settings are such then the formatting SHALL change. This one really grinds on those that haven't done international apps.
Bob

Collapse -
Re: combobox
by Kees_B Forum moderator / August 23, 2014 1:50 AM PDT
In reply to: Is there any hope?

- In the properties of the combobox, what is the format?
- What are the windows settings (regional) for date format?

Kees

Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

The Samsung RF23M8090SG

One of the best French door fridges we've tested

A good-looking fridge with useful features like an auto-filling water pitcher and a temperature-adjustable "FlexZone" drawer. It was a near-flawless performer in our cooling tests.