简体   繁体   中英

how to set startDate to beginning of the month in bootstrap datepicker?

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)});

您可以这样:

<%= text_field_tag 'start_date', Date.today.beginning_of_month.strftime('%d/%m/%Y'), :class => 'calendar1' %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM