0
votes

I imported xml file to excel and the date format is yyyy-MM-ddTHH:mm:ssZ , How could i change the format to yyyyy-mm-dd HH:MM:ss or to Unix format?

Thanks!

2

2 Answers

0
votes

Go to ur excel and do this

search for ur format type and done

Update 1: Okay try that

 Sub ChangeDateFormat()

Application.ScreenUpdating = False

Dim CurrentCell As Range
Dim LastRow As Long
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True

LastRow = Range("A" & Rows.Count).End(xlUp).Row 'Get The Last Row in Column Change A as Needed

For Each CurrentCell In Range("A1:A" & LastRow) ' Loop through all cells. Change Column as needed

   If InStr(CurrentCell.Value, "/") <> 0 Then 'To make sure only convert non converted ones

     RegEx.Pattern = "(\d{4})/(\d{2})/(\d{4}) (\d{2}):(\d{2}):(\d{2})" ' Seperate all parts of imported Data into groups
       CurrentCell.Value = RegEx.Replace(CurrentCell.Value, "$3.$2.$1 $4:$5") ' Change order of groups and place into cell.

   End If

Next

Application.ScreenUpdating = True

End Sub

Change the code as u need

Update 2: try that

format(now(), "yyyy-MM-dd hh:mm:ss")
0
votes

The string "yyyy-MM-ddTHH:mm:ssZ" can be changes to date with the following function оr to replace "T" with " " and "Z" with ""

Function StrToDate(str As String) As Date
    StrToDate = CDate(Replace(Replace(str, "T", " "), "Z", ""))
End Function