Home > OS >  How to obtain most recent date and time from a column
How to obtain most recent date and time from a column

Time:12-14

I'm trying to obtain the most recent date and time from a column using VBA excel.

The issue here is that once I run the macro, I obtain the correct most recent date, but the time obtained remains in a 00:00:00 value as shown in the image.

enter image description here

CodePudding user response:

The problem is in your Split function. Dates are stored as decimal numbers with the integer part being the number of days since 31/12/1899 and the decimal part being the fraction of a day (or time).

And VBA is US-centric (decimal as dot) in many areas

When you Split on the decimal and return the first element in the resultant array, you are effectively removing the time portion from your datetime value, hence the time is missing from your result.

Change your Max_Date= line to read:

Max_Date = Format(max_datetime, "dd/mm/yyyy hh:mm:ss")
  • Related