My favorites | Sign in
Project Home Wiki
Search
for
ChangingDateFormat  
How to change the date format
Phase-Implementation, Phase-Deploy
Updated Feb 4, 2010 by timchar...@gmail.com

Some of the available date formats

Name Format
:natural January 2, 2007 5:30 pm
:hyphen_ampm 2007-01-31 5:30 pm
:iso_date 2008-31-01 17:30
:finnish 31.1.2008 17:30
:american 1/31/2008 5:30 pm

... for more formats, look at the top of lib/calendar_date_select.rb

( note - this only works when you are using using <%= calendar_date_select_includes %> in your layout )

Implementing your own date formats

ChangingDateFormatCustom

Comment by akk...@gmail.com, Sep 12, 2007

Does it works in 24 hour ssytem?

Comment by project member timchar...@gmail.com, Sep 26, 2007

You can create your own format to do so. If you feel nice, feel free to submit it for inclusion in the calendar_date_select code base!

Comment by rolf.gue...@gmail.com, Jan 15, 2008

Can anyone tell me what I am doing wrong when trying to do the above changes to the bottom of environment.rb and getting:

dependencies.rb:266:in `load_missing_constant': uninitialized constant CalendarDateSelect (NameError?)

Comment by antono.v...@gmail.com, Jan 15, 2008

/ iso format for CalendarDateSelect / Date.prototype.toFormattedString = function(include_time) {

str = this.getFullYear() + "-" + Date.padded2(this.getMonth() + 1) + "-" +Date.padded2(this.getDate());

if (include_time) { hour=this.getHours(); str += " " + this.getHours() + ":" + this.getPaddedMinutes() } return str; }

Date.parseFormattedString = function (string) {

var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
"( ([0-9]{1,2}):([0-9]{2})?" + "?)?)?)?";
var d = string.match(new RegExp?(regexp, "i")); if (d==null) return Date.parse(string); // at least give javascript a crack at it. var offset = 0; var date = new Date(d1?, 0, 1); if (d3?) { date.setMonth(d3? - 1); } if (d5?) { date.setDate(d5?); } if (d7?) { date.setHours(d7?); } if (d8?) { date.setMinutes(d8?); } if (d10?) { date.setSeconds(d10?); } if (d12?) { date.setMilliseconds(Number("0." + d12?) 1000); } if (d14?) {
offset = (Number(d16?) 60) + Number(d17?); offset = ((d15? == '-') ? 1 : -1);
}

return date;

}

Comment by antono.v...@gmail.com, Jan 15, 2008

fuck!

Comment by kev.z...@gmail.com, Jan 31, 2008

FYI, if you're geting the error rolf.guescini points out:

load_missing_constant': uninitialized constant CalendarDateSelect (NameError?)

Make sure you add the CalendarDateSelect.format line at the very end of your environments.rb and not inside the Rails::Initializer.run method

Comment by fannar, Mar 11, 2008

There are more current formats like:

CalendarDateSelect.format = :finnish

Comment by TiBen...@gmail.com, Mar 13, 2008

Hi there,

i got problems with saving values in the database as datetime. Every time i load the calendar with a standard value and save it without any changes it will be broke. The Datetime in the database will be return to zero.

So i start search an found sth. in the calendar_date_select.rb. If i change the function date_format_string to: def date_format_string(time=false)

@@format[:date] + " " + ( time ? @@format[:time] : "" )
end

It will works fine. As u can see i just enter a space between the date and the time.

Is there any reason why there isn't any space?

Realy good calendar, realy good work

Comment by skyli...@gmail.com, Apr 17, 2008

Hey guys, I'm using the plugin, it works great on dates in the default 10 years range, but when I try and save a date in 1960 (year_range => 50) the date is passed back ok, but gets set to NULL on the DB insert. I'm sure I'm missing something simple but I've no idea what.

Comment by r...@occumed.com.au, Apr 27, 2008

Sometimes there is an issue with old dates < 1970. I suggest using DateTime? to parse the value before you run the insert.

Comment by ravivard...@gmail.com, May 26, 2008

Hi All,

I want to select only futures date from calender. Only enable future dates and disable past dates. please give solution for this
Comment by project member timchar...@gmail.com, May 26, 2008

Please use the mailing list for questions like this

Comment by cheri.an...@gmail.com, Jul 3, 2008

How would I get the difference in days between two dates? Could you please point me to an example of how this is done?

Thanks!

Comment by cheri.an...@gmail.com, Jul 3, 2008

Nevermind, I figured it out. I just put the calendar_select format into the hyphen_ampm format and subtracted the two dates.

Thanks for the cool plugin!

Cheri

Comment by damianma...@gmail.com, Oct 28, 2008

Great plugin, but the documentation is poor. I have to read all the comments to just change the format... Thanks to all!

Comment by bol...@gmail.com, Oct 29, 2008

How does one change the date format? :format => :iso_date? :date_format => :iso_date? :iso_date => true?

The text above does not seem to answer the question.

Thanks

Comment by bol...@gmail.com, Oct 29, 2008

found the answer in the comments:

CalendarDateSelect.format = :iso_date

Thanks for the plugin!

Comment by drg...@gmail.com, Nov 17, 2008

This should be in the documentation, you can do it in the layout - when you include the calendar. <%= calendar_date_select_includes :style=>"default", :format =>"iso_date", :locale=>"fi" %>

Comment by drg...@gmail.com, Nov 17, 2008

sowwy, only works for locale and style -

CalendarDateSelect.format = :iso_date
needs to go in environment.rb

Comment by keeb...@gmail.com, Dec 4, 2008

Still doesn't work. Can someone just lay it out like I'm a 5 year old?

Comment by psutton1...@gmail.com, Dec 16, 2008

In the calendar_date_select.rb scroll down to the @@format and change it from :natural to your desired format.

Comment by frode.me...@gmail.com, Jan 20, 2009

The problem here is that if you set

CalendarDateSelect.format = :euro_24hr

it works for the popup-result/the result string, but not inside the actual pop. Inside the popup, it still shows AM/PM.. Why is this.

Comment by rdeju...@gmail.com, Feb 11, 2009

So I to am a 5 year old. How do I set this up to have a dynamic date format?

Comment by rdeju...@gmail.com, Feb 11, 2009

I am apparently a little older, maybe 6, but I finally it working. This is what works: <% CalendarDateSelect.format=(:hyphen_ampm )%> <%= calendar_date_select_includes %> <%= calendar_date_select_tag opts[:field], '' ,:popup => 'force' %>

Comment by markram...@gmail.com, Mar 30, 2009

Is it possible to change the format at runtime?

I tried with

<% if current_language.downcase == "de" %>
    <% CalendarDateSelect.format=(:finnish )%>
    <%= calendar_date_select_includes %>
  <% else %>
    <% CalendarDateSelect.format=(:natural )%>
    <%= calendar_date_select_includes %>
  <% end %>
Comment by project member timchar...@gmail.com, Mar 30, 2009

Yes, it would be. You would have to execute that before you include the calendar_date_select javascript includes, however.

Comment by han...@gmail.com, Apr 1, 2009

where do I put the format code ? "CalendarDateSelect.format = :finnish "

Comment by kawz...@yahoo.com, Jun 28, 2009

i have been trying to use my Prototype knowledge to enforce changing the date format but with no success. is it possible to change the format using javascript call?

i am not using RoR and need to change the format please.

trying.. new CalendarDateSelect( $('Birthdate'), {year_range:40, format:'iso_date'} );

no clue what do to next other than changing the toFormattedString() function..

any help will really be appreciated.

Comment by project member timchar...@gmail.com, Jun 28, 2009

That's exactly what you need to do: change the toFormattedString() function. Each date format implementation takes code.

The date format is set depending on which date format you include, it's as simple as that.

Comment by vadimp...@gmail.com, Feb 1, 2010

I have a ugly solution but it works

var CustomCalendarDateSelect = Class.create(CalendarDateSelect, {
  updateValue: function($super) {
    $super();
    var d = this.selected_date;
    var day = d.getDate() < 10 ? ("0" + d.getDate()) : d.getDate();
    var month = d.getMonth() < 10 ? ("0" + parseInt(d.getMonth() + 1)) : parseInt(d.getMonth() + 1);
     
    var str = day + "/" + month + "/" + d.getFullYear();
    this.target_element.value = str;
  },
  parseDate: function($super)
  {
    var value = $F(this.target_element).strip();
    $super();
    if (this.selection_made) {
        this.selected_date.setFullYear(value.split('/')[2],parseInt(value.split('/')[1]) - 1,parseInt(value.split('/')[0]));
        this.date = this.selected_date;
    }
  }
});

Comment by hipha...@gmail.com, Jun 24, 2010

what the hell...!!! Document is baaaaaaaaaaaaaaad.

Comment by senn...@gmail.com, Feb 23, 2011

KEY WORD you can edit calendar_date_select.rb and set @@format=:iso_date


Sign in to add a comment
Powered by Google Project Hosting