Ruby date format difference between %-d vs %e or "no-padded" vs "blank-padded"

Viewed 281

In Ruby documentation, there are two very similar values for formatting a date(time) string

  1. %-d described as no-padded (1..31)
  2. %e described as blank-padded ( 1..31)

What's the difference between these two?

1 Answers

The difference between these two is the following:

%-d will print out the number without leading zero nor space ex:

DateTime.new(2016, 02, 01, 16, 00).strftime('%m/%-d/%Y')
> "02/1/2016"

%e will print out a leading space but not a leading zero

DateTime.new(2016, 02, 01, 16, 00).strftime('%m/%e/%Y')
> "02/ 1/2016"
Related