Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Showing date parsing problem using "%m/%d/%Y" as format. According to system level documentation (man 3 strptime) the formats between strftime and strptime should be reflexive. At the clib level, they are, but at the ruby level, they are not.
$ irb -r date
irb(main):001:0> format = "%m/%d/%Y"
=> "%m/%d/%Y"
=> "08/18/2013"
irb(main):003:0> Date.parse(,format)
ArgumentError: invalid date
from (irb):3:in `parse'
from (irb):3
from /Users/tamara/.rubies/ruby-2.0.0-p427/bin/irb:12:in `<main>'
=> "2013-08-18"
irb(main):005:0> Date.parse(
=> #<Date: 2013-08-18 ((2456523j,0s,0n),+0s,2299161j)>
irb(main):006:0> quit
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
$ irb -v
irb 0.9.6(09/06/30)
$ ./test
Current time from strftime: 08/18/2013
Parsed time:
Month: 8
Day: 18
Year: 2013
#include <stdio.h>
#include <time.h>
int main(void)
time_t now;
now = time(NULL);
struct tm *now_tm;
now_tm = gmtime(&now);
char *format = "%m/%d/%Y";
char buf[25];
strftime(buf, sizeof(buf), format, now_tm);
printf("Current time from strftime: %s\n", buf);
struct tm now2_tm;
strptime(buf, format, &now2_tm);
printf("Parsed time: \n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment