Functions Sys.Date() and Sys.time() are going to return present date and time respectively.
Function strntime("time, date or both" format="date format") is going to create date and time structure according to value and format you are providing.
Format in strntime function is going to be created based on keys in next list:
- %Z for timezone
- %z for offset from GMT
- %Y for 4 digits year
- %y for 2 digits year
- %X for locale specific time
- %x for locale specific date
- %W for week of the year
- %w for day of the week
- %S for seconds
- %p for AM/PM
- %M for minute
- %m for month
- %j for day of the year
- %I for hours in 12 hours format
- %H for hours in 24 hours format
- %d for date
So in next example a <- strntime("12.04.2023 22:24:36", format="%d.%m.%Y. %H:%M:%S"), after this functions is executed, variable a is going to hold value of "12.04.2023. 22:24:36". But variable a is not a string in this case. In order to print string out, you would have to call function format(a, "print me %H hours and %M minutes"). In this case, to we are going to get "print me 22 hours and 24 minutes" printed to our screen.
In order to use date and time object for calculations, we need to use additional package called lubridate.
Now we can simply use our date and time object like a<- a + hours(2) + minutes(18) in order to add additional 2 hours and 18 minutes to it.
For video tutorial, check the link below.
No comments:
Post a Comment