Change Values of DateTimePicker - asp.net

I am creating a MVC application, and the user's have asked that on the datetimepicker if the values could be switched to intervals of 6.
So on this part of the datetimepicker:
Is there a way to change the values to 00, 06, 12, 18, etc?
Any help is appreciated.

I found it!
The original datetimepicker was based off of this:
fillMinutes = function () {
var table = widget.find('.timepicker-minutes table'),
currentMinute = viewDate.clone().startOf('h'),
html = [],
row = $('<tr>'),
step = options.stepping === 1 ? 5 : options.stepping;
while (viewDate.isSame(currentMinute, 'h')) {
if (currentMinute.minute() % (step * 4) === 0) {
row = $('<tr>');
html.push(row);
}
row.append('<td data-action="selectMinute" class="minute' + (!isValid(currentMinute, 'm') ? ' disabled' : '') + '">' + currentMinute.format('mm') + '</td>');
currentMinute.add(step, 'm');
}
table.empty().append(html);
},
so I changed the step = options.stepping === 1 ? 5 : options.stepping; to:
step = options.stepping === 1 ? 6 : options.stepping;

Related

Automatically obtain date and time when I type in a cell but in separate columns at google sheets

I'm new around here, apologies in advance. I go with my question: I have a google spreadsheet with multiple cells and two sheets. What I am trying to do is that when I type a value in any cell in column 2, the time and date will automatically appear in the adjacent cell. I have gotten this code, which only worked for me on Sheet 1:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "HOJA 1-HF-SSB" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date()).setNumberFormat("dd-MM-yyyy HH:mm");
}
}
}
Then I have managed to simplify it and adapt it to work on both sheets of the document:
function onEdit(e) {
var sheets = ["HOJA 1-HF-SSB", "HOJA 2-FM-DMR"];
if (sheets.indexOf(e.source.getActiveSheet()
.getName()) === -1 || e.range.columnStart !== 2) return;
e.range.offset(0, 1)
.setValue(new Date()).setNumberFormat("dd-MM-yyyy HH:mm");
}
My questions are: Is there a way to get the date and time to go in separate columns? That is, when I fill in column 2, the date is written in column 3 and the time in column 4?
My final goal, apart from separating the date and time, is to determine later (I don't know how to do it) and highlight which values ​​recorded in column 2 are duplicated on the same date, comparing them with the automatic dates in column 3, regardless of the time. Thank you and excuse me, I am a very newbie!
Try (only for column #2)
function onEdit(e) {
var sheets = ["HOJA 1-HF-SSB", "HOJA 2-FM-DMR"];
if (sheets.indexOf(e.source.getActiveSheet().getName()) === -1 || e.range.getColumn() !== 2) return;
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
var newdate = year + "/" + month + "/" + day;
e.range.offset(0, 1).setValue(newdate).setNumberFormat("dd-MM-yyyy");
e.range.offset(0, 2).setValue(new Date()).setNumberFormat("HH:mm");
}
https://docs.google.com/spreadsheets/d/1NYxNfoPM6l_PJTPBDxEth2n-T_H0o03FG6C0OMDuJOo/copy

FullCalendar change date format

When the user select a range of dates on the calendar, a modal opens and the input fields of initial and final dates are auto complete with the dates selected previously. The problem is that they are displaying in this format YYYY-MM-DD and I want it to be DD-MM-YYYY. I have tried everything but nothing seems to work.
Here is where I get the dates and fill the inputs:
select: function (info) {
$('#ModalAdd').modal('show');
$('#ModalAdd').appendTo("body");
$('#activoReservar').val($('#selectActivoReserva option:selected').text());
$('#fechaInicial').val(info.startStr);
var endDate = new Date(info.end);
var beforeDay = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate() - 1).toISOString().slice(0,10);
$('#fechaFinal').val(beforeDay);
},
And here are the things I have tried:
$('#fechaInicial').val(info.startStr.format('ddd, DD-MM-YYYY')); //i tried with dd and a single d too. And without any d
$('#fechaFinal').val(beforeDay.format('ddd, DD-MM-YYYY'));
you may create another function (which you can use anywhere else too),
pass a date to that function and return your desired format.
The sample function might look like as follow:
function dateToDMY(date) {
var d = date.getDate();
var m = date.getMonth() + 1; //Month from 0 to 11
var y = date.getFullYear();
return '' + (d <= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y;
}
And you may call the function from select or any other place as follow:
select: function (selectionInfo) {
var startStr = dateToDMY(selectionInfo.start);
}

Calculate Sum of Oracle Apex Tabular Form Cell

There is a column as Amount in my oracle apex tabular form. I need to calculate SUM of all fields under this column while data is being entered and display on a Display only field below the tabular form.
I think this can be done using JavaScript and call that JavaScript at onchange of Amount column.
But I don't know how to calculate SUMof Amountcolumn in my oracle apex tabular form. How could I do this?
Add the following JavaScript code into the Page HTML Header property:
<script type="text/javascript">
function tot_cal()
{
var f5=new Array();
var tol=0;
f5=document.getElementsByName("f05"); /*f05 is Apex array which holds the data*/
for(i=0;i<f5.length;i++){
tol = (tol*1) + (f5[i].value.replace(/,/g, '') * 1);
}
/* alert(tol); */
$s('P10_AMOUNT_VALUE', tol.formatMoney(2,',','.'));
}
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) {
var n = this,
decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
decSeparator = decSeparator == undefined ? "." : decSeparator,
thouSeparator = thouSeparator == undefined ? "," : thouSeparator,
sign = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};
</script>
Tabular Form Element/Element Attributes property of the Amount column:
onchange="tot_cal();"

How can I compare two dates in format dd mmm yyyy?

I would like to compare two dates in this format dd mmm yyyy, compare validators wont work because of the format and custom validator is server side validation. I would like to have a clinet side validation. What would be the best way to do it? if you have any examples or links please let me know.
I dont know if there are options availables with ajax, jquery or javascript that can do this?
Cheers
Since JavaScript natively converts from MMM dd, yyyy, this would be one approach:
var date1Str = "09 Sep 2011";
var date2Str = "04 May 2012";
var dateParts = date1Str.split(" ");
var newDateStr = dateParts[1] + " " + dateParts[0] + ", " + dateParts[2];
var date1 = new Date( newDateStr );
var dateParts = date2Str.split(" ");
var newDateStr = dateParts[1] + " " + dateParts[0] + ", " + dateParts[2];
var date2 = new Date( newDateStr );
if ( date1 > date2 )
...
There are tons of links on the net to do date parsing in JavaScript and plenty of libraries that make it easier. Remember that culture plays a part. "Oct" is in English but in German it will be "Okt".
Here's a simple class you can use to compare dates; the convert function has been adjusted to accommodate your format:
<script type="text/javascript">
var dates = {
convert:function(d) {
return (
d.constructor === Date ? d :
d.constructor === Array ? new Date(d[1],d[0],d[2]) :
d.constructor === Number ? new Date(d) :
d.constructor === String ? new Date(d) :
typeof d === "object" ? new Date(d.year,d.month,d.date) :
NaN
);
},
compare:function(a,b) {
return (
isFinite(a=this.convert(a).valueOf()) &&
isFinite(b=this.convert(b).valueOf()) ?
(a>b)-(a<b) :
NaN
);
},
inRange:function(d,start,end) {
return (
isFinite(d=this.convert(d).valueOf()) &&
isFinite(start=this.convert(start).valueOf()) &&
isFinite(end=this.convert(end).valueOf()) ?
start <= d && d <= end :
NaN
);
}
}
</script>
Credit for this class belongs to #some: https://stackoverflow.com/a/497790/879420

LINQ to SQL Ordering from external method

It seem to me that this was hard...
var MostRated = (from p in db.Posts
let AverageRating = CalculateAverageRatingFromPost(p)
where p.PostStatus == Convert.ToInt32(PostStatusEnum.Published.Value) && p.IsDeleted == false
orderby p.PublishedDate descending
select new
{
PostUrl = Common.PostUrl(p.Section.Name, p.Permalink),
Title = Common.TrimString(p.Title, 50),
Excerpt = Common.TrimString(p.Excerpt, 80),
AverageRate = CalculateAverageRating((from pr in db.Ratings
where pr.ObjectType == Convert.ToInt32(ObjectTypeEnum.Post.Value) && pr.ObjectID == p.ID
select pr).SingleOrDefault()),
PublishedDate = new DateHelper().DateTimeInWords(p.PublishedDate.Value)
}).OrderByDescending(o => o.AverageRate).Take(5).ToList();
and the other method is
private Decimal CalculateAverageRating(Rating pr)
{
if (pr != null)
{
Decimal Average = ((1 * (Decimal)pr.Star1) + (2 * (Decimal)pr.Star2) + (3 * (Decimal)pr.Star3) + (4 * (Decimal)pr.Star4) + (5 * (Decimal)pr.Star5)) / ((Decimal)pr.Star1 + (Decimal)pr.Star2 + (Decimal)pr.Star3 + (Decimal)pr.Star4 + (Decimal)pr.Star5);
return Average;
}
else
{
return 0;
}
}
I get this run time error "no supported translation to SQL".
What i want is to get lists of the posts, and do a small quick calculations of the rating and then sort those from highest to low and take 5 posts only.
Thanks
I haven't tested this, but try defining the function as an Expression object.
Expression<Rating, Decimal> CalculateAverageRating =
pr => (Decimal)(
pr == null ? 0 :
(pr.Star1 + 2*pr.Star2 + 3*pr.Star3 + 4*pr.Star4 + 5*pr.Star5)
/(pr.Star1 + pr.Star2 + pr.Star3 + pr.Star4 + pr.Star5));

Resources