how to save string datetime to datetime field in database?
im using rails 3 app. and i cant save my datetime value from my datetime picker to my database in sql server 2005. i keep getting invalid date. any suggestions?
i have this in my model:
scope :available, lambda {
|checkin, checkout| {
:select => 'amenities.*',
:order => 'id',
:conditions => ["
amenities.id NOT IN
(
SELECT aa.id from amenities aa, amenity_list al WHERE
aa.id = al.amenities_id AND
(
(? BETWEEN al.checkin AND al.checkout) OR
(? BETWEEN al.checkin AND al.checkout)
)
)",
checkin, checkout
开发者_JAVA技巧 ]
}
}
here's my controller:
def step2
@cart = current_cart
checkin = params[:checkin]
checkout = params[:checkout]
@amenities = Amenity.available(checkin, checkout)
session[:checkin] = checkin
session[:checkout] = checkout
end
application.js
$(function() {
var dates = $( "#checkin, #checkout" ).datetimepicker({
dateFormat: 'mm/dd/yyyy hh:MM:ss TT',
buttonImageOnly: true,
buttonImage: 'images/icons/cal.png',
showOn: 'button',
showAnim: 'blind',
defaultDate: "+1w",
changeMonth: false,
numberOfMonths: 2,
minDate: new Date(),
onSelect: function( selectedDate ) {
var option = this.id == "checkin" ? "minDate" : "maxDate",
instance = $( this ).data( "datetimepicker" ),
date = $.datetimepicker.parseDate(
instance.settings.dateFormat ||
$.datetimepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datetimepicker( "option", option, date );
}
});
});
Have you tried Date.parse(checkin) ?
精彩评论