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

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;

Related

Working with Date, Time in Google Apps Script

I need help with some quick coding with google apps script, linking to my googlesheets spreadsheet.
In the googlespreadsheets, I have a cell with the value “26-Jun-2020”. It is a date.
I want to use google apps script to calculate the number of days difference between that date (“26-Jun-2020”) and today’s day, but it won’t do the calculation for me somehow.
If I print only “expiry_date[i]” using Logger.log(expiry_date[i]), it will provide the output “Fri Dec 17 2021 01:00:00 GMT-0500 (Eastern Standard Time) “
function Put_Options_Expiry_Alert() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Long equity (sell puts)");
//var timeZone = AdsApp.currentAccount().getTimeZone(); //Get timezone of current spreadsheet
var status = sheet.getRange("F:F").getValues();
var expiry_date = sheet.getRange("M:M").getValues();
var potential_capitaloutlay_USD = sheet.getRange("Z:Z").getValues();
Logger.log("Length of status = " + status.length);
Logger.log("Length of expiry_date = " + expiry_date.length);
Logger.log("Length of potential_capitaloutlay_USD = " + potential_capitaloutlay_USD.length);
for (var i = 0; i < status.length; i++) {
if (status[i] == "Entered") { //Evaluate if this is a live Put position
//Calculate the time difference of two dates using date2. getTime() – date1. getTime();
//Calculate the no. of days between two dates, divide the time difference of both the dates by no. of milliseconds in a day (1000*60*60*24)
Logger.log("expiry date is = "+expiry_date[i]);
Logger.log("today's date is = "+Date());
var days_to_expiry = dateDiffInDays(expiry_date[i],Date());
Logger.log(days_to_expiry);
}
}
}
// Function that returns the number of days difference between DateA and DateB
// DateA and DateB are javascript Date objects
function dateDiffInDays(DateA, DateB) {
var milliseconds_per_day = 1000 * 24 * 60; // number of milliseconds in a day
const utcA = Date.UTC(2021, DateA.getMonth(), DateA.getDate());
const utcB = Date.UTC(2020, DateB.getMonth(), DateB.getDate());
return Math.floor((utc2 - utc1) / milliseconds_per_day);
}
function timeDiffDays(Start, End) {
var day = 86400000;
var t1 = new Date(Start).valueOf();
var t2 = new Date(End).valueOf();
var d = t2 - t1;
return Math.floor(d / day);
}

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 refresh displayed date in CalendarExtender?

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()

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