+ Reply to Thread
Results 1 to 4 of 4

Combine A Date And A Time To Create A Unique Date

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Combine A Date And A Time To Create A Unique Date

    As I understand a true date serial in Excel contains both date and time values. The information that is provided is based on the formatting applied to the serial.

    I have a date from cell F22 formatted at 2019-04-28. Reformatted to include the time, I get 2019-04-28 12:00:00 AM
    I have a textbox on a userform where the user enters a time. I use CDate formatted with "h:mm AM/PM" to convert it to a true time value (stime = CDate(Me.uf9a_tb_cstart.Value)) . If 7:00 is entered, the resulting value of stime = 7:00 AM. If I reformat it to include the date I get an obscure 30-12-99 7:00 AM.

    My question is, how can I combine the date from the cell value of F22 and the time value from the textbox into one value (stime) with a VBA solutioN?
    As an example using the data mentioned, a value formatted as "dd-mm-yy h:mm:ss am/pm" will result in stime = 28-04-19 7:00 AM?

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Combine A Date And A Time To Create A Unique Date

    Do you mean like this?
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Combine A Date And A Time To Create A Unique Date

    Thank you jindon! Exactly what I was looking for and not a complicated solution.

    Question: What is the purpose of the "$" following Format?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Combine A Date And A Time To Create A Unique Date

    When you are in VBE, go to [View] - [Object Browser]

    Enter String$ in to Search box, then you will see string functions, one with/without $.
    If you click on one of them, you can see returning data type from the function and with $, it returns String explicitly, and Variant when not $.

    It is said that it would be faster with $.

    HTH.

+ 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. [SOLVED] Combine Date and Time
    By hq7878 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-09-2018, 01:18 AM
  2. Formula to create unique ID using DATE & TIME
    By floato in forum Excel General
    Replies: 3
    Last Post: 03-21-2016, 04:13 PM
  3. Need to separate date/time from a single cell and create a date/time chart
    By slicksilver79 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 06-19-2014, 09:48 PM
  4. Date & Time combine
    By thong127 in forum Excel General
    Replies: 9
    Last Post: 03-04-2014, 02:33 PM
  5. Unable to combine Date and Time
    By sajeel in forum Excel General
    Replies: 3
    Last Post: 06-15-2010, 03:18 PM
  6. Combine date and time
    By BN-CD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2006, 11:31 AM
  7. Combine Date & Time Cells
    By Ron Lieber in forum Excel General
    Replies: 2
    Last Post: 01-31-2006, 04:15 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