Ruby | DateTime to_date() function Last Updated : 09 Jan, 2020 Comments Improve Suggest changes Like Article Like Report DateTime#to_date() : to_date() is a DateTime class method which returns the Date object which denotes itself. Syntax: DateTime.to_date() Parameter: DateTime values Return: the Date object which denotes itself. Example #1 : Ruby # Ruby code for DateTime.to_date() method # loading library require 'date' # declaring DateTime value date_a = DateTime.new(2019, 8, 10, 4, 10, 9) # declaring DateTime value date_b = DateTime.new(2019, 8, 10.5) # declaring DateTime value date_c = DateTime.new(2019, 8, 10, 4, 10, 9, Rational(4, 24)) # to_date method puts "DateTime to_date form : #{date_a.to_date}\n\n" puts "DateTime to_date form : #{date_b.to_date}\n\n" puts "DateTime to_date form : #{date_c.to_date}\n\n" Output : DateTime to_date form : 2019-08-10 DateTime to_date form : 2019-08-10 DateTime to_date form : 2019-08-10 Example #2 : Ruby # Ruby code for DateTime.to_date() method # loading library require 'date' # declaring DateTime value date_a = DateTime.new(2019, 8, 10, 5) # declaring DateTime value date_b = DateTime.parse('10 Aug 2018 04:10:06+04:30') # declaring DateTime value date_c = DateTime.new(2019, 8, 10, 4, 10, 9, '+03:00') # to_date method puts "DateTime to_date form : #{date_a.to_date}\n\n" puts "DateTime to_date form : #{date_b.to_date}\n\n" puts "DateTime to_date form : #{date_c.to_date}\n\n" Output : DateTime to_date form : 2019-08-10 DateTime to_date form : 2018-08-10 DateTime to_date form : 2019-08-10 Comment More infoAdvertise with us Next Article Ruby | DateTime to_date() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby DateTime-class Similar Reads Ruby | DateTime to_datetime() function DateTime#to_datetime() : to_datetime() is a DateTime class method which returns the self DateTime object. Syntax: DateTime.to_datetime() Parameter: DateTime values Return: the self DateTime object. Example #1 : Ruby # Ruby code for DateTime.to_datetime() method # loading library require 'date' # dec 1 min read Ruby | DateTime to_s() function DateTime#to_s() : to_s() is a DateTime class method which returns string representation of the DateTime object. Syntax: DateTime.to_s() Parameter: DateTime values Return: string representation of the DateTime object. Example #1 : Ruby # Ruby code for DateTime.to_s() method # loading library require 2 min read Ruby | DateTime zone() function DateTime#zone() : zone() is a DateTime class method which returns the time zone for a given DateTime object. Syntax: DateTime.zone() Parameter: DateTime values Return: the time zone for a given DateTime object. Example #1 : Ruby # Ruby code for DateTime.zone() method # loading library require 'date' 2 min read Ruby | Time to_datetime() function Time#to_datetime() is a Time class method which returns a date time object of itself. Syntax: Time.to_datetime() Parameter: Time values Return: a date time object of itself. Example #1 : Ruby # Ruby code for Time.to_datetime() method # loading library require 'time' # declaring time a = Time.new(201 2 min read Ruby | DateTime to_time() function DateTime#to_time() : to_time() is a DateTime class method which returns the time object which denotes the DateTime object self. Syntax: DateTime.to_time() Parameter: DateTime values Return: duplicate DateTime object self and resets its to_time. Example #1 : Ruby # Ruby code for DateTime.to_time() me 2 min read Ruby | DateTime sec() function DateTime#sec() : sec() is a DateTime class method which returns the seconds of the DateTime object. Syntax: DateTime.sec() Parameter: DateTime values Return: seconds of the DateTime object. Example #1 : Ruby # Ruby code for DateTime.sec() method # loading library require 'date' # declaring DateTime 2 min read Ruby | Date day() function Date#day() is a Date class method which returns the day of the month from 1 to 31. Syntax: Date.day() Parameter: Date values Return: the day of the month from 1 to 31. Example #1 : Ruby 1=1 # Ruby code for Date.day() method # loading date require 'date' # declaring Date a = Date.new(2019, 1, 1) # de 2 min read Ruby | DateTime second() function DateTime#second() is a DateTime class method which returns the second value of the DateTime object. Syntax: DateTime.second() Parameter: DateTime values Return: the second value of the DateTime object. Example #1 : Ruby # Ruby code for DateTime.second() method # loading library require 'date' # decl 2 min read Ruby | DateTime jd() function DateTime#jd() : jd() is a DateTime class method which returns a DateTime object denoting the given chronological Julian day number. Syntax: DateTime.jd() Parameter: DateTime values Return: DateTime object denoting the given chronological Julian day number. Example #1 : Ruby # Ruby code for DateTime. 1 min read Like