+ Reply to Thread
Results 1 to 4 of 4

Extracting Date (year,month,day) from cell with Date (year,month,day,time)

  1. #1
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263

    Extracting Date (year,month,day) from cell with Date (year,month,day,time)

    Hi All,

    I have a cell with a date and time in and I need VBA to extract just the date and then pass this to a variable. I assume a Date variable type is the best one but how do I truncate the cell so it's just the date? I've tried the obvious thing of using:

    Application.WorksheetFunction.Date()

    But it seems this function can't be access via VBA? Does anyone have any suggestions?

    Thanks

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,476

    Re: Extracting Date (year,month,day) from cell with Date (year,month,day,time)

    Assuming your variable is named Dte and is Dim'med as Date data type and assuming the date/time value is in cell A1...

    D = Int(Range("A1").Value)

  3. #3
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263

    Re: Extracting Date (year,month,day) from cell with Date (year,month,day,time)

    Great, thanks! A lot simpler than I thought but yes the date is just an integer isn't it? Obvious really! :D

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,476

    Re: Extracting Date (year,month,day) from cell with Date (year,month,day,time)

    In Excel and VBA, date/times are floating point numbers... the integer part is the number of days offset from some "date zero" and the decimal part is the fraction of a 24-hour day for time. The formatting so that dates "look" like dates is for humans only... the computer never really sees the date the way you do... it just sees the floating point number.

+ 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: 06-26-2019, 11:46 AM
  2. Extracting Month and Year from Date
    By aquinn_21 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-27-2016, 06:37 PM
  3. Extracting Month/Year from a Date
    By skillsguy in forum Excel General
    Replies: 4
    Last Post: 01-01-2015, 09:37 PM
  4. Need to convert Month/Date/Year to Year/Month/Date so excel will recognize
    By juliettelam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2014, 04:17 PM
  5. Replies: 3
    Last Post: 09-04-2013, 10:49 AM
  6. Replies: 4
    Last Post: 05-31-2013, 11:20 AM
  7. [SOLVED] Extract Year or Month only from a cell with date and time
    By djaurit in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2013, 04:03 PM

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