将“ YYYY-MM-DD HH:MM”时间戳格式化为日期

时间:2018-09-20 14:06:15

标签: r date-formatting

我有一个包含两列的数据集,分别是房价和销售日期(和时间),尽管所有时间均为00:00。日期列的格式为YYYY-MM-DD 00:00。

我想从列中删除时间,以便只留下日期,然后可以按顺序对其进行排序并绘制在图形上。

1 个答案:

答案 0 :(得分:1)

如果您的日期采用您指定的格式,则可以像这样简单地使用Sub test() Dim number(100) As Double Dim target(100) As Range Dim currcell As Range Dim currline As Integer Dim currcolumn As Integer For currcolumn = 3 To 15 Step 3 number(currcolumn) = Cells(currcolumn, 2) Set target(currcolumn) = Cells(currcolumn, 2) For currline = 2 To 20 If Abs(Cells(currline, currcolumn) - 0.5) < number(currcolumn) Then number(currcolumn) = Abs(Cells(currline, currcolumn) - 0.5) Set target(currcolumn) = Cells(currline, currcolumn) End If Next currline MsgBox "column: " & currcolumn & " number:" & target(currcolumn) & " at line: " & target(currcolumn).Row Next currcolumn End Sub

as.Date()

Try it out