w3resource

Retrieve System Date and Time in R

R Programming: Basic Exercise-27 with Solution

Write a R program to create the system's idea of the current date with and without time.

Sample Solution :

R Programming Code :

# Print a message indicating the system's idea of the current date with and without time
print("System's idea of the current date with and without time:")

# Print the current date (without time) according to the system
print(Sys.Date())

# Print the current date and time according to the system
print(Sys.time())

Output:

[1] "System's idea of the current date with and without time:"
[1] "2018-11-13"
[1] "2018-11-13 12:33:23 UTC"                         

Explanation:

  • Prints a descriptive message:
    • print("System's idea of the current date with and without time:")
    • Displays a string indicating that the following output will show the current date and time.
  • Prints the current date:
    • print(Sys.Date())
    • Sys.Date() retrieves and prints the current system date in the format "YYYY-MM-DD".
  • Prints the current date and time:
    • print(Sys.time())
    • Sys.time() retrieves and prints the current system date and time, including hours, minutes, and seconds, in the format "YYYY-MM-DD HH:MM

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to create a Dataframes which contain details of 5 employees and display summary of the data.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/r-programming-exercises/basic/r-programming-basic-exercise-27.php