PDA

View Full Version : Dates and Times in an Array



BENatUSGS
06-13-2011, 10:42 AM
Hey all,
I’m having some issues with date and time in my code. I have values that are being stored in an array, p(k), and being moved to another workbook. When I attempt to combine date and time that initially look like this… 6/30/83 and 16:30… I am getting a result that looks like 6/30/19830.680555555555555.
Here is my code that attempts to move the time and dates…
Cells(1, 5).Value = p(3) + p(4)
p(3) being the stored date value and p(4) being the time.
Is there a different way that these values must be stored in order for them to be reformatted correctly?
Let me know,
Ben

Kenneth Hobs
06-13-2011, 12:16 PM
Did you check the numeric format to see that they were date and time? You might want to use CDATE() or CDBL() for the date number. To set the format for the cell:
Cells(1, 6).NumberFormat = "m/d/yyyy h:mm"

BENatUSGS
06-13-2011, 01:54 PM
That is exactly what I needed to do. Thanks a lot!
Ben