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
]
}
}
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) ?
Related
So this is the SQL I'm trying to emulate currently.
SELECT * FROM direct_messages AS T
INNER JOIN (SELECT sender_id, receiver_id, MAX(sent_at) AS sent_at FROM direct_messages WHERE (sender_id = '2' OR sender_id = '3') AND (receiver_id = '3' OR receiver_id = '2') GROUP BY sender_id, receiver_id) A
ON A.sender_id = T.sender_id AND A.sent_at = T.sent_at;
This is the entity for the table
#ObjectType()
#Entity()
export class DirectMessages {
#Field(() => ID)
#PrimaryKey()
id!: number;
#Field(() => String)
#Property()
senderID!: string;
#Field(() => String)
#Property()
receiverID!: string;
#Field(() => String)
#Property()
message!: string;
#Field(() => Date, { nullable: true })
#Property({ nullable: true })
readAt?: Date;
#Field(() => Date)
#Property()
sentAt: Date = new Date();
#Field(() => Date)
#Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
}
This is what I've written in the queryBuilder so far
const subQuery = await er
.createQueryBuilder('DirectMessages')
.select(['sender_id', 'receiver_id', 'MAX(sent_at)'])
.where({ $or: [{ senderID: '2' }, { senderID: '3' }] })
.andWhere({ $or: [{ receiverID: '3' }, { receiverID: '2' }] })
.groupBy(['sender_id', 'receiver_id'])
.getKnexQuery();
const queryResults = await er
.createQueryBuilder('DirectMessages')
.select('*')
.withSubQuery(subQuery, 'A')
.join('A.sender_id', 'T', undefined, 'innerJoin')
.execute('all', true);
The subQuery is right but I have no idea how to then join that temporary table to the DirectMessages table. I appreciate the help!
I have the following code in react native:
const handleRefresh = useCallback(async () => {
const date = await AsyncStorage.getItem(`lastRequestDate`);
console.log('date: ', date);
console.log('type of: ', typeof date === 'string' ? date : '');
const previousDate = new Date(typeof date === 'string' ? date : '');
// const previousDate = new Date('2021-06-02T00:52:46.892Z');
console.log('previous date: ', previousDate);
}, [user]);
When I console log previousDate I get Date { NaN } but if I console log date I get "2021-06-02T00:52:46.892Z". If I console log const previousDate = new Date('2021-06-02T00:52:46.892Z'); I get the correct date. However if I replace the string by date variable the error appears (Date { NaN }) (const previousDate = new Date(typeof date === 'string' ? date : '');)
Try to save the condition in a variable and use that in the new Date(...)
const newDate = typeof date === 'string' ? date : ''
const previousDate = new Date(newDate);
i have added two date fields. i want to retrieve the data between those two table.PaymentDate and ChequePostedDate are two fields. so i need to get the rows between two dates.
simply search content have two date fields. i want to retrieve the rows(data) between those two dates
public function __construct($modelClass, $fields = null, $filters = null) {
$fields = new FieldList(array(
DateField::create('PaymentDate','Payment Date : from')
->setConfig('dateformat', 'yyyy-MM-dd')
->setConfig('showcalendar', true)
->setAttribute('placeholder','YYYY-MM-DD')
->setDescription(sprintf(
_t('FormField.Example', 'e.g. %s', 'Example format'),
Convert::raw2xml(Zend_Date::now()->toString('yyyy-MM-dd'))
)),
DateField::create('ChequePostedDate','cr Date : to')
->setConfig('dateformat', 'yyyy-MM-dd')
->setConfig('showcalendar', true)
->setAttribute('placeholder','YYYY-MM-DD')
->setDescription(sprintf(
_t('FormField.Example', 'e.g. %s', 'Example format'),
Convert::raw2xml(Zend_Date::now()->toString('yyyy-MM-dd'))
)),
));
$filters = array(
'PaymentDate' => new PartialMatchFilter('PaymentDate'),
'ChequePostedDate' => new PartialMatchFilter('ChequePostedDate'),
);
parent::__construct($modelClass, $fields, $filters);
}
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null) {
$dataList = parent::getQuery($searchParams, $sort, $limit, $existingQuery);
$params = is_object($searchParams) ? $searchParams->getVars() : $searchParams;
$query = $dataList->dataQuery();
if(!is_object($searchParams)) {
if (isset($params['PaymentDate'])&& $params['ChequePostedDate'] ) {
$query->where('`PaymentNote`.PaymentDate BETWEEN \''.$params['PaymentDate'].' \' AND \''.$params['ChequePostedDate'].'\'');
}
}
return $dataList->setDataQuery($query);
}
}
You can also use WithinRangeFilter something like the following, but you need to use the setMin(), setMax() methods as per this forum response: https://www.silverstripe.org/community/forums/form-questions/show/11685
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null) {
$dataList = parent::getQuery($searchParams, $sort, $limit, $existingQuery);
$params = is_object($searchParams) ? $searchParams->getVars() : $searchParams;
$query = $dataList->dataQuery();
if(!is_object($searchParams)) {
if (!empty($params['PaymentDate'] && !empty($params['ChequePostedDate'])) {
return $dataList->filter('PaymentDate:WithinRange', [$params['PaymentDate'], $params['ChequePostedDate']]);
}
}
return $dataList;
}
i solved it..
simply remove $filters
$filters = array(
// 'PaymentDate' => new PartialMatchFilter('PaymentDate'),
//'ChequePostedDate' => new PartialMatchFilter('ChequePostedDate'),
);
then it works
I'm using this code for create a booking system:
http://jsfiddle.net/9zjwdypc/
This example working fine, but I can't add the internalization and others option.
I tried this sample code:
$('#dpd1').datepicker({
language: 'it'
});
$('#dpd1').datepicker({
format: "dd-mm-yyyy",
weekStart: 1,
language: "fr",
autoclose: true,
todayHighlight: true
});
$('#dpd2').datepicker({
format: "dd-mm-yyyy",
weekStart: 1,
language: "fr",
autoclose: true,
todayHighlight: true
});
$(window).load(function(){
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('#dpd1').datepicker({
onRender: function(date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
if (ev.date.valueOf() > checkout.date.valueOf()) {
var newDate = new Date(ev.date)
newDate.setDate(newDate.getDate() + 1);
checkout.setValue(newDate);
}
checkin.hide();
$('#dpd2')[0].focus();
}).data('datepicker');
var checkout = $('#dpd2').datepicker({
onRender: function(date) {
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
checkout.hide();
}).data('datepicker');
});
adding:
<script src="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/js/locales/bootstrap-datepicker.fr.js"></script>
The same using this:
$(document).ready(function(){
$.fn.datepicker.defaults.language = 'it';
});
This is the error:
TypeError: $.fn.datepicker.dates is undefined
You have include french language file and then try to use italian language...
Im new to datatables, and Im having this issue thats bugging me for a while.
for example, I'm trying to edit the 5th column, but I want to disable it for part of the rows..
is it possible? cause I don't seem to find the way..
$('td:eq('5')', oTable.fnGetNodes()).editable('/'+appName+'/GetGenWidgetTableDataServlet',
{
type : 'text',
tooltip: 'Click to Edit',
indicator: 'Saving...',
placeholder : '',
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[2],true,true );
},
"submitdata": function ( value, settings ) {
debugger
var iPos = oTable.fnGetPosition( this );
var colPos = iPos[2];
iPos = iPos[0];
if(iPos!=null)
{
var aData = oTable.fnGetData( iPos );
var vRowType = aData[0];
var iId = aData[2];
var moduleID = iId.split("$")[0];
var unitID = iId.split("$")[1];
var processID = iId.split("$")[2];
var riskID = iId.split("$")[3];
var controlID = iId.split("$")[4];
}
return {
"Token": idhref,
"moduleID" :moduleID,
"unitID": unitID,
"processID" :processID ,
"riskID": riskID,
"controlID": controlID,
"rowType":vRowType,
"Action": "saveRow",
"columnName": aoCols[colPos]["Id"]
};
},
"height": "25px",
"width": "50px"
}
We use the datatables editable plugin (https://code.google.com/p/jquery-datatables-editable/ ) and it allows you to set a sReadOnlyCellClass. We set that class in the datatable fnRowCallBack function based on the values in the row.
You could set an "editable" class in your fnRowCallBack
oTable = $('#resultTable').dataTable( {
...
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
if ( aData["something"] == "This row should be editable" )
{
nRow.className = "editable";
}
return nRow;
}
...
});
and modify your selector to
oTable.$('tr.editable td:eq(5)').editable( ...)