Hi @Astik_Chawda,
Welcome to the RStudio Community Forum.
With a few tweaks your code gives this:
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
appointments <- data.frame(AppointmentRegistration = c("2015-08-07T08:19:19Z",
"2015-08-15T10:19:19Z",
"2015-08-31T14:19:19Z"))
appointments
#> AppointmentRegistration
#> 1 2015-08-07T08:19:19Z
#> 2 2015-08-15T10:19:19Z
#> 3 2015-08-31T14:19:19Z
# Had to change format to include %Y (not %y) and %M (not %m) and %H (not %h)
# as.Date() is not sufficient here as it doesn't keep the "time" part.
appointments$DateTimeOfAR <- as.POSIXct(appointments$AppointmentRegistration,
format="%Y-%m-%dT%H:%M:%SZ")
# Can now extract the hour alone
appointments$Houroftheday <- hour(appointments$DateTimeOfAR)
appointments
#> AppointmentRegistration DateTimeOfAR Houroftheday
#> 1 2015-08-07T08:19:19Z 2015-08-07 08:19:19 8
#> 2 2015-08-15T10:19:19Z 2015-08-15 10:19:19 10
#> 3 2015-08-31T14:19:19Z 2015-08-31 14:19:19 14
Created on 2022-06-09 by the reprex package (v2.0.1)
Hope this helps.