+ Reply to Thread
Results 1 to 7 of 7

Read Excel file Date

  1. #1
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    50

    Question Read Excel file Date

    Hello,

    I am building a GUI which reads an other Excel file.
    The read file contains some date, when I get these data, I have some integer instead of date.
    How should I proceed ?

    For example, the file I read have the following date :
    2005/4/1

    When I get it in VBA, I obtain : 38443. Can this integer be converted into the initial date ?

    I have the same question for the time :
    0:05:00

    When I get the data, I obtain :
    0.00347222222222222

    Thank you in advance.
    Last edited by oro77; 01-23-2012 at 06:48 AM.

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Read Excel file Date

    Excel stores dates in a numerical value representing the number of days elapsed since 30th December 1899 (assuming not using the 1904 date system). To derive the date that this value represents you could use this:



    Please Login or Register  to view this content.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Read Excel file Date

    use
    Please Login or Register  to view this content.



  4. #4
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Read Excel file Date

    Thank you very much, it works perfectly.

    I have an additional question :
    How do I format the date correctly, my GUI get the data and display it on my sheet.
    I have taken the "0:05" data from the original sheet and it automatically puts it like : "12:05:00 AM"

    How to keep the same format : "0:05" ?

    Thank you in advance.
    Last edited by oro77; 01-23-2012 at 06:03 AM.

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Read Excel file Date

    Are you placing the date back into an Excel sheet or into a textbox or something similar (ie not an Excel cell)? Assuming it is a cell, then you just need to directly place the extracted value in the cell and amend the formatting of the cell to display the date how you want. if the latter, then you can use the Format function to construct a string to the required format:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Read Excel file Date

    Thank you, it works. I placed my data in Excel cells.

  7. #7
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Read Excel file Date

    Declare the variable as date and not as integer or long.

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