6

I always get the dates like shown in Column A, but I need them as shown in column C. How can I do it without having to create column B helper? I need that because the hours and minutes mess up what I want to achieve after this.

Column A

Time with hours and minutes:

22/05/2015 14:57
11/06/2015 15:40
28/05/2015 08:27
26/05/2015 14:51
25/05/2015 14:18
25/05/2015 15:51

Column C

Time without hours and minutes:

22/05/2015 
11/06/2015 
28/05/2015 
26/05/2015
25/05/2015
25/05/2015

I managed to solve this by creating a column B that converts to text

=Text(A2;"DD-MM-AAAA")

and then column C converts text to value

=Data.value(B2)

While this process works, it causes me a lot of unnecessary data and I wonder if I can do this automatically with a macro in one step. I also want the number dates in column C always equal to the number of dates in column A and dates in the same order.

6
  • 2
    Why not just re-format column A to hide the time ?? May 10, 2016 at 16:28
  • 2
    @findwindow good idea, but the LEFT function is used for string manipulation so you would wrap it in a DATEVALUE function =DATEVALUE(LEFT(A1,10)) May 10, 2016 at 16:30
  • @MacroMan I was just testing you =P
    – findwindow
    May 10, 2016 at 16:30
  • 1
    @findwindow I know, never doubted you for a second! May 10, 2016 at 16:31
  • @Gary'sStudent guessing OP wants it in column C? Then again, copy/paste into C then format XD
    – findwindow
    May 10, 2016 at 16:32

4 Answers 4

22

To get the date only use:

=INT(A2)

And format to date. This works because dates in excel are the number of days since December 31st, 1899 so for example May 10th, 2016 is 42500 days since.

And the Time is a decimal based on 24 hours. So, May 10th, 2016 12:00:00 equates to 42500.5.

So to get just the date we remove the decimal. INT() does just that.

6
  • I feel outsmarted for not finding this :O. This is formula works perfect!
    – carlos_cs
    May 10, 2016 at 16:47
  • 3
    @carlos_cs we all have moments where we overthink the problem and make it more complicated than it needs to be. Sometimes it takes others to help point out the easier method. May 10, 2016 at 16:48
  • @carlos_cs lol we all feel outsmarted with Scott ^_^; Edit: I shouldn't say we but I.
    – findwindow
    May 10, 2016 at 16:50
  • =INT(NOW()) is returning "5/26/2016 0:00"?
    – Adavid02
    May 26, 2016 at 16:50
  • 1
    @Adavid02 Now format the cell to show only the date and not the time. Either using "Short Date" or a custom format of m\d\yyy May 26, 2016 at 16:54
4

This was tagged with [excel-vba] so I'll offer a full column time stripping solution.

The Range.TextToColumns method makes quick work of stripping off the date portion of a datetime. The fieldinfo parameter can specify the DMY format you are using and discard the time portion with the appropriate xlColumnDataType. While most TextToColumns commands are made 'in place', an alternate destination is available if specified. When specifying an alternate destination, the original data is left intact.

Option Explicit

Sub stripTime()
    Dim i As Integer
    With Worksheets("Sheet1")
        'check to see if A1 is a date or a column text label
        i = Abs(Not IsDate(.Cells(1, 1).Value))
        With .Range(.Cells(1 + i, "A"), .Cells(.Rows.Count, "A").End(xlUp))
            .TextToColumns Destination:=.Cells(1, "C"), DataType:=xlFixedWidth, _
                           FieldInfo:=Array(Array(0, xlDMYFormat), Array(10, xlSkipColumn))
            'optionally assign a custom number format
            .Offset(0, 2).NumberFormat = "[color10]dd-mmm-yyyy_)"
            'optionally autofit the column width
            .Offset(0, 2).EntireColumn.AutoFit
        End With
    End With
End Sub

After processing you are left with your original datetimes in column A and true date-only values in column C.

         strip_date_out_of_datetime

2
  • 1
    Wow, this is exactly what I asked for!
    – carlos_cs
    May 13, 2016 at 15:07
  • Be careful with rows.count, because it counts also formatted cells.
    – musbach
    May 15, 2022 at 10:47
0

you can use =Today() OR =NOW() then change

0

10-04-2020 3:09:42 PM transforms to 10.04.2020

Using this formula:

=IF(ISBLANK(A1),"",TEXT(A1,"DD.MM.YYYY"))

Not the answer you're looking for? Browse other questions tagged or ask your own question.