Reputation: 1535
I have two text field one for start date and one for end date. For start date i want to set beginning of the month as default. But not getting how to accomplish that.
This is my code
<%= javascript_include_tag 'bootstrap-datepicker.js'%>
<%= form_tag '/mine', :class => "form-inline" do %>
<%= label_tag 'start_date', 'Start Date' %>
<%= text_field_tag 'start_date', nil, :class => 'calendar1' %>
<%= label_tag 'end_date', 'End Date' %>
<%= text_field_tag 'end_date', nil, :class => 'calendar' %>
<% end %>
<script>
$(".calendar").datepicker({format: "dd/mm/yyyy"});
$(".calendar1").datepicker({format: "dd/mm/yyyy"});
</script>
I tried like this by referring here
$(".calendar1").datepicker({format: "dd/mm/yyyy", startDate: Date.today.beginning_of_month});
or
$(".calendar1").datepicker({format: "dd/mm/yyyy",setDate date(Date.today.beginning_of_month)});
Upvotes: 0
Views: 1069
Reputation: 928
You can do like this:
<%= text_field_tag 'start_date', Date.today.beginning_of_month.strftime('%d/%m/%Y'), :class => 'calendar1' %>
Upvotes: 1