method
to_date
![Some documentation Importance_1](https://d2vfyqvduarcvs.cloudfront.net/images/importance_1.png?1349367920)
v3.0.9 -
Show latest stable
-
2 notes -
Class: String
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (38)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (1)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
Register or
log in
to add new notes.
lulalala -
June 15, 2012
MikeBlyth -
November 28, 2012 - (>= v3.0.0)
![Default_avatar_30](https://www.gravatar.com/avatar/009994c3985985809d2d644bd49aa1c2?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
Month-first date string no longer parses correctly
The following date format won’t be parsed correctly:
'06/15/2008'.to_date
Use this instead:
Date.strptime("6/15/2012", '%m/%d/%Y')
![Default_avatar_30](https://www.gravatar.com/avatar/156670da3e6214b1f82b0816497b252b?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
String to date conversion not necessarily symmetric
Note that converting from Date to String and back again is not necessarily symmetric, because the conversion to string may result in a format that is not properly converted by `to_date`.
For one thing, `to_date` sets the century argument in _parse to false. Thus if the default date format has a two-digit year, like the :short one, the century will be dropped.
Date.today.to_s.to_date #=> Mon, 28 Nov 0012