How Can I add date to 1 year. in X++ - axapta

How Can I add date to 1 year. I have field with date. now i want to add another field which add 1 year to previous field (date) in X++ code
Ex: 19/10/2010 to 18/10/2011

Maybe:
TransDate dt = 19\10\2010;
info(strfmt("date is %1",nextYr(dt)));

You want the date before the same date next year:
nextYr(19\08\2011 - 1)
The function nextYr gives you the same date, so you have to subtract by 1.

TransDate dt = 19\10\2010;
TransDate dt_res = mkdate(dayofmth(dt), mthofyr(dt), year(dt) + 1 ) - 1;

I got an Answer ..
Create a display method on the table
Diplay Date m1()
{
date d;
d = this.fieldDate + 364;
return d;
}
just drag & drop it on the form design (grid, Group -like)
exetue it 1 year will be added to previous Date

Related

using doctrine and querybuilder, between two date

I want to retrieve some data using queryBuilder, the condition is to use a datetime field on parent table and pass it to where condition, the child table have two date start and end, the whole condition is to select parent row depend on date between the two date in child table
the code is:
$qb->select('parent,child')
->from($this->class, 'parent')
->innerJoin('parent.childTable', 'child')
//other join
// and where
//CONDITION -> startdate <= $date AND enddate >= $date
$betweenDates = $qb->expr()->andX(
$qb->expr()->gt("child.dateStart", "parent.datetime"),
$qb->expr()->lt("child.dateEnd", "parent.datetime")
);
//CONDITION 4 -> enddate == NULL
$endDateNull = $qb->expr()->isNull( 'child.dateEnd');
$dates = $qb->expr()->orX($betweenDates, $endDateNull);
// take care of dateEnd if it's null
$qb->expr()->andX($dates);
the problem is the where condition not work and the select still give me childs not respect date condition
any help would be greatly appreciated.

How to get first date and last date from given month name and Year

In my page I have on dropDown ddMonth and ddYear ...ddMonth shows jan,Feb,mar etc. ddYear as 2014,2015... . By using this How can I get the first date and last date from this 2 dropdown (ddmonth and ddYear) by using asp.net.
The first date of always starts with 1 so you can create date using day as 1
DateTime dt = new DateTime(year, month, 1);
For last date of month you can add 1 to month and subtract on day from it.
DateTime dt = (new DateTime(year, month, 1).AddMonths(1)).AddDays(-1);

How to select records in ax based on month or year only?

I am new to AX development. I was looking for to_char equivalent in AX so that i can select records based on month and year only. I want to select all the records for one particular month only irrespective of the date.
You will have to use a date range instead.
date d = today();
date d1 = startMth(d);
date d2 = endMth(d);
while select ledgerTrans
where ledgerTrans.TrandDate >= d1 &&
ledgerTrasn.TransDate <= d2
{
...
}

c# linq group by fortnight or x number of days?

Hi I'm trying to work out how would you group items into the first and 2nd half of each month for a given year and month?
i.e.
Say for example I have to list the name of item on the 6th of every month and the 15th of every month.
say for example I have
Flight Name Flight Date
Flight 1 01/07/2012
Flight 2 12/07/2012
Flight 3 18/07/2012
Flight 4 28/07/2012
how would i split it up so I'd like to group flights by fortnights within a year/month
i.e
Flights For July week 1 and 2 - 2012
Flights for July week 3 and 4 - 2012
so this is what I have so far..
eventually it'll have to be some kind of view model using automapper etc i am not sure as of yet how it'd get that neatly into some kind of ViewModel form...
var flightEntities = from f in flightsAsViewModels
select new
{
YearGroups = from flightYearGroup in context.Flights
group flightYearGroup by flightYearGroup.FlightDateTime.Year
into yearGroup
orderby yearGroup.Key descending
select new
{
Year = yearGroup.Key,
MonthGroups = from flightMonthGroup in yearGroup
group flightMonthGroup by flightMonthGroup.FlightDateTime.Month
into monthGroup
orderby monthGroup.Key ascending
select new {
Month = monthGroup.Key,
HalfMonthGroups = from months in monthGroup
group months by (months.FlightDateTime.Day <= 15 ? 1 : 2) into splitMonthFlights
orderby splitMonthFlights.Key
select new { WhichHalfOfMonth = splitMonthFlights.Key, Flights = splitMonthFlights }
}
}
};
I hereby pasted Linq code for the requirement. But not sure, this still can be achievable in shortest way. Please let me know if so.
var monthGroupedDates = from d in dates
group d by d.Month into fd
select new { Month = fd.Key, Dates = fd };
foreach (var g in monthGroupedDates)
{
var groupByHalf = from n in g.Dates
group n by (n.Day <= 15 ? 1 : 2) into gd
orderby gd.Key
select new { WhichHalf = gd.Key, Dates = gd };
foreach (var gh in groupByHalf)
{
string printString = (gh.WhichHalf == 1 ? "First" : "Second") + " week dates are:";
foreach (var h in gh.Dates)
{
printString += h.ToString("dd/MM/yyyy") + ";";
}
Console.WriteLine(printString);
}
}
Please note, dates are one which is mentioned in your requirement. If its Linq with SQL, this may need slight alterations.
Raj

retrievind date in asp.net

I need to retrieve the current date in asp.net and then compare that with the date given by the user in textbox1.text(mm/dd/yyyy format), if date date given is greater than current date then error else add 4months2days with that date and display it in textbox2.text.
help me please,
thanking you guys,
Indranil
DateTime dateToCompare;
if(DateTime.TryParse(textbox1.text, out dateToCompare))
{
DateTime current = DateTime.Now;
TimeSpan ts = current - dateToCompare;
if (ts.Ticks < 0)
{
//display error
}
else
textbox2.text = dateToCompare.AddMonths(4).AddDays(2).ToString("mm/dd/yyyy");
}
}
I'm not going to write your code, but in .NET you can use ToString to specify a date format, TryParse to get a date out of a string. And AddDays, AddMonths etc to manipulate a date.
In javascript, there's no simple way to format output, but you can use getMonth etc to prompt the individual values and concatenate a string from that. You can use a combination of getDate and setDate to manipulate dates. It automatically corrects for new months, i.e. if you run myDate.setDate( myDate.getDate() + 60 ) it'll actually increment by 60 days; you won't end up with a weird date like May 74th.
Keep in mind that months in javascript are zero-based, ie January is 0, February is 1, etc.
You can create a new date in javascript by new Date(yy, mm, dd) or new Date('yy/mm/dd'), so you could string-manipulate an input and create a date from that.
To compare two dates, you can subtract one from the other, and get the difference in milliseconds.
if ( dateA - dateB < 0 ) // dateB is greater than dateA (occurrs later)
and
var diff = Math.abs(dateA - dateB) // difference in ms, no matter which date is greater
DateTime date1 = new DateTime();
if(DateTime.TryParse(textbox1.text, out date1)){
if (date1.CompareTo(DateTime.Now) > 0)
{
//Error code here
}else
{
textbox2.text = date1.AddMonths(4).AddDays(2);
}
}

Resources