I get the date as a string, as shown below:
"September 1998"
I tried as Date.parse("September 1998") , but it did not work.
Date.parse("September 1998")
How to convert it to a ruby ββdate object that returns a string in the above format?
Date.strptime('September 1998', '%B %Y') . However, it will be September 1, 1998, since the dates of the objects represent, well, dates.
Date.strptime('September 1998', '%B %Y')
You can use a chronic stone :
require 'chronic' t = Chronic.parse('September 1998', :guess => true) #returns a Time object => 1998-09-01 00:00:00 -0700 t.to_date #convert to Date object => <Date: 1998-09-16 ((2451073j,0s,0n),+0s,2299161j)>
Chronic was created by Tom Preston-Werner , who also co-created Github.
Just add the missing "1":
str ="September 1998" p Date.parse("1 " + str) # => #<Date: 1998-09-01 ((2451058j,0s,0n),+0s,2299161j)>
Source: https://habr.com/ru/post/987380/More articles:RewriteRule does not work with the plus symbol (+ or *) - regexhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/987376/use-a-lens-to-replace-a-specific-element-of-a-keyvalue-list&usg=ALkJrhjbG9AjrlPzffzOIb8uh2T0CJcETwCalculate average field value in embedded documents / array - mongodbhow to match a specialized string to a specified integer - c ++how to combine dimensional arrays - jsonhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/987381/adding-custom-roles-to-azure-mobile-services-user-google-twitter-facebook-microsoft&usg=ALkJrhj0oQuKTMkb7QrFnieT90QbqAh5dgCreate a fragment transition, for example, the Contacts application? - javaSelect only direct children from the element with Sass - cssDisqus in Ionic APP - javascriptHow to delete the entire line if it has a word? - c #All Articles