+ Reply to Thread
Results 1 to 2 of 2

Date format problem!

  1. #1
    Forum Contributor
    Join Date
    04-13-2006
    Location
    London
    Posts
    102

    Angry Date format problem!

    I am from the UK, so our date format is dd/mm/yyyy.

    My code builds a string from some other strings to make a date:

    strDOBDay = "11"
    strDOBMonth = "08"
    strDOBYear = "1961"


    I then build a new string, strDateOfBirth, as follows:

    strDateOfBirth = strDOBDay & "/" & strDOBMonth & "/" & strDOBYear

    Which is 11th August, 1961.

    However, when my code adds it to a worksheet, something strange happens! It appears on the worksheet as "08/11/1961". When I reformat the cell, it has made the date the 8th November, not 11th August!

    The code to add the string to my worksheet is:

    ActiveCell.Offset(1, 8) = Format(strDateOfBirth, "dd/mm/yyyy")

    I ought to point out that if I change the format to:

    ActiveCell.Offset(1, 8) = Format(strDateOfBirth, "dd/mmmm/yyyy")

    Then the cell shows as "11-Aug-61".

    This is really annoying me! What on earth is going on?

    Why would the date be changed to 8th November using the first format, but stay as the correct date of 11th August using the second format????

    I would really be grateful if someone could solve this!!!!

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    04-13-2006
    Location
    London
    Posts
    102

    Unhappy

    Unbelievably, I've solved it! It's not what I would call an easy solution, but it seems to work.

    If I make the format as:

    ActiveCell.Offset(1, 8) = Format(strDateOfBirth, "m/d/yyyy")

    Then I get "11/08/1961", which is 11th August 1961. Why it works is a mystery. Perhaps someone could tell me why????

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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