henkv
henkv

Reputation: 31

Excel DATEVALUE function independent of international settings

In my Excel workbook, I copy some date information from another (text) source. To be able to do calculations with these dates, I use the function "DATEVALUE".

Example: cell A1 contains the text 20 february 2014, cell B1 contains the formula =DATEVALUE(A1). This works as expected: I get the number of days since 1-1-1900, which I can display in any date notation imaginable.
No problem so far. Even through this is not a typical date notation in the English language, DATEVALUE recognizes february as the month name and acts accordingly.

Now, when I open this workbook on a computer with different international settings (Windows 7: Control panel -> Region and language -> Formats), cell B1 gives a #VALUE error. Only when I change the text in A1 to 20 februari 2014 (Dutch date string, in accordance with the international settings on that PC), DATEVALUE gives the same result as before.

Apparently, the DATEVALUE uses the international settings to convert from the string to a date.

Is there some way to prevent this, in order words:

Upvotes: 3

Views: 6398

Answers (2)

CRondao
CRondao

Reputation: 1903

You can try this formula:

=DATE(RIGHT(A1;4);MATCH(MID(A1;4;3);{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"};0);LEFT(A1;2))

Date admits arguments always in the order year, month, day

I admit that day values are always 2 digits.

If you dont mind to write the months abrev. in a range then you can get a much more shorter formula.

Depending on your regional settings you may need to replace field separator ";" by ","

Upvotes: 6

Gary's Student
Gary's Student

Reputation: 96773

Try the following UDF :

Public Function EngDate(s As String) As Date
    Dim dayz As Long, monthz As Long, yearz As Long
    ary = Split(LCase(s), " ")
    dayz = CLng(ary(0))
    yearz = CLng(ary(2))
    mnth = Split("january,february,march,april,may,june,july august,september,october,november,december", ",")
    For i = 0 To 11
        If ary(1) = mnth(i) Then
            monthz = CLng(i + 1)
            Exit For
        End If
    Next i
    EngDate = DateSerial(yearz, monthz, dayz)
End Function

It will process inputs like:

day as number, single space, month as text, single space, year as a number

Upvotes: 0

Related Questions