How to refresh displayed date in CalendarExtender? - asp.net

I've this code that changes the maximum date of a second Calendar Extender to 90 days after the date that has been defined in a first one and minimum to the same it has been selected on the first and it works right except for one thing.
var cal2 = $find("calendar2");
var fecha = cal._selectedDate;
var date = fecha.getDate() + 90;
var year = fecha.getFullYear();
var month = fecha.getMonth();
var todayDate = new Date(year, month, date);
cal2._startDate = cal._selectedDate;
cal2._selectedDate = fecha;
cal2._switchMonth(fecha);
cal2._endDate = todayDate;
Problem is that if I first seelct a date on cal, dates are properly shown in cal2, but I select one on cal again then cal2 doesn't display in the same month that cal, what's much worse it displays to select days that would be now impossible to select and in fact you can select them unless you go back first to month mode.
Any idea on how to "refresh" the behavior of the second CalendarExtender?
Thank you.

you can use this method.
Sys.Extended.UI.CalendarBehavior.prototype.refresh = function () {
this._isOpen = true;
this._ensureCalendar();
this.invalidate();
this._isOpen = false;
}
When you add the method only call:
cal2.refresh()

Related

Need first day of last month and Last day of next month from current date in Asp.Net

Need first day of last month and Last day of next month from current date in Asp.Net
Eg : Current date 02/12/2019
first day of last month = 01/11/2019
Last day of next month = 31/01/2020
var myDate = DateTime.Now;
var firstDateOfLastMonth = myDate.AddMonths(-1);
firstDateOfLastMonth = firstDateOfLastMonth.AddDays(-firstDateOfLastMonth.Day + 1);
var lastDayOfNextMonth = myDate.AddMonths(1);
lastDayOfNextMonth = new DateTime(lastDayOfNextMonth.Year, lastDayOfNextMonth.Month, DateTime.DaysInMonth(lastDayOfNextMonth.Year, lastDayOfNextMonth.Month));
You may have to refer DataTime C# for more info
please try below line of code:
DateTime lastMonthdate = DateTime.Now.AddMonths(-1);
var lastMonth = new DateTime(lastMonthdate.Year, lastMonthdate.Month, 1);
var lastDayOfNextMonth = lastMonth.AddYears(1).AddMonths(1).AddDays(-1);

How to minus the date from the current date in PL/SQL

I am new to SAP and XMI. I have a report that when the page loads it automatically gets the data for the current date. But i need the data to go a day backwards so for eg if today is the 29/06/2016 it shouldn't show any data for today but it should load for the 28/06/2016 which is -1 day back.
If i click on 27/06/2016 then it must minus 2 days back from the current day of the 29/06/2016.
So how do I use the current date to minus off the date that was inputed by the user so that PL/SQl knows how many days previously to go back?
function Start()
{
if (document.frmMain["DATEFROM"].value == '{DATEFROM}')
{
var MONTH_NAMES=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var SD = new Date();
var ED = new Date();
var dateInMs = SD.getTime();
SD.setTime(dateInMs);
var month = MONTH_NAMES[SD.getMonth()];
var day = SD.getDate();
var year = SD.getFullYear();
var hours = SD.getHours();
var minutes = SD.getMinutes();
document.frmMain["DATEFROM"].value = LZ(day) + "-" + month + "-" + year + " 23:59:59";
}
else {
} }
HTML
<tr>
<input name="dtpDATEFROM" type="button" id="dtpDATEFROM" onclick="MM_callJS('popUpCalendar(frmMain.dtpDATEFROM, frmMain.DATEFROM, \'dd-mmm-yyyy 00:00:00\')')" value="...."> </font></td>
</tr>
What was tried:
SELECT *
FROM table
WHERE TRUNC(Date_Production )=trunc(sysdate) to_date('2016/06/29','yyyy/mm/dd')
If you're just trying to subtract days from a given date you can just do "date - n":
select trunc(sysdate) today, trunc(sysdate)-1 yesterday, trunc(sysdate)-2 two_days_ago from dual;

Javascript Moment.js add a day to a date in milliseconds

I am trying to add a day to a date in milliseconds.
The code I am using is bellow.
var x = 1450612800000;
var timeFrame = 'days'
x = moment(x).add(timeFrame, 1);
console.log(x['_i']) //returns 1450612800000
Here is the fix:
var x = 1450612800000;
var timeFrame = 'd'
var newDay = moment(x).add(tf, 1);
console.log('newDay');
//Get New Date in Milliseconds format
console.log(newDay.valueOf());
//Get New Date in Date Format
console.log(newDay.toDate());
Take a look at this StackOverflow answer: https://stackoverflow.com/a/28132227/3692354
_i isn't what you want to use here - that's the input that was used to create the moment object. I think what you want to use instead is moment's valueOf function: http://momentjs.com/docs/#/displaying/unix-offset/

How to get end date

How to get End Date after selection of Start date from drop down list.
I am selecting startdate from dropdowns and I am showing last date in label.
For example- If I am selecting "January" from first dropdown. Date "1" from second dropdown.
Then Label1.text become last date i.e. 31 december.
How can I do this ?
Please try below code
int month = DateTime.ParseExact(Convert.ToString(ddlMonth.SelectedValue), "MMMM", CultureInfo.CurrentCulture).Month;
int day = Convert.ToInt32(ddlDay.SelectedValue);
int year=DateTime.Now.Year;
DateTime date = new DateTime(year,month, day);
//Use AddDays for add and substract days
date.AddDays(-1);
string str=String.Format("{0:m}", date);
There are many ways of doing it . You can do it in javascript as well as in asp.net. have a page method of make a $.ajax call with the data selected
$.ajax({
url : '',
data : 'month=MONTH&day=DAY',
success : function(result){
$("#labelid").text(result);
}
})
C# part
int maxDay = DateTime.DaysInMonth(DateTime.Now.year,month);
//validate the selected day is equal or less than the maxDay
DateTime StartDate = new DateTime(DateTime.Now.Year, Convert.ToInt16(dropdownMonth.SelectedIndex) + 1, Convert.ToInt16(dropdownDays.SelectedIndex) + 1);
DateTime PreDayDate = StartDate.AddDays(-1); lblEndDateValue.Text = PreDayDate.ToString();
In case you do not want to do AJAX you have to do the postback and handle it then onward.
using
DateTime.AddDays Method
you can do this
DateTime StartDate = new DateTime(DateTime.Now.Year, Convert.ToInt16(UrMonthNameDropDown.SelectedIndex+1), Convert.ToInt16(UrDateDropdown.SelectedIndex));
DateTime PreDayDate = StartDate.AddDays(-1);
substract 1 day from your start date.
source:http://msdn.microsoft.com/en-IN/library/system.datetime.adddays.aspx

DateTime [ Last week , Last month periods ]

I need to setup last week , last month periods on changing dropdownlist
I'm making
switch (DDL.SelectedIndex)
{
case 0:
{
// last week
this.TextBox3.Text = DateTime. //Previos week first day
this.TextBox4.Text = DateTime. //Previos week last day
} break;
case 1:
{
// last mouth
this.TextBox3.Text = DateTime.// Previos month first day
this.TextBox4.Text = DateTime.// Previos month last day
} break;
}
So is there some ways how can I select date values like I want ?
also , I've got AJAX calendar extender on text boxes
thank you.
Something like this, I think:
int dayOfWeekNumber = (int)DateTime.Today.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
var previosWeekFirstDay = DateTime.Today.AddDays(-7 - dayOfWeekNumber);
var previosWeekLastDay = previosWeekFirstDay.AddDays(6);
var previosMonthFirstDay = DateTime.Today.AddMonths(-1);
previosMonthFirstDay = previosMonthFirstDay.AddDays(-previosMonthFirstDay.Day + 1);
var previosMonthLastDay = previosMonthFirstDay.AddDays(DateTime.DaysInMonth(previosMonthFirstDay.Year, previosMonthFirstDay.Month) - 1);
Edited: see Fredrik Mörk comment.

Resources