Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Thursday, 16 January 2014

find the first and last day of month


DateStartMth and dateEndMth in ax 2012

    1.public date dateStartMth(date _date)

    2.client server public static date dateEndMth(date transDate)

Date and UTCDateTime interval for previous month

This code calculates the first and last date of the previous month

static void EP_dateMonthInterval(Args _args)

{
   date            fromDate;
   date            toDate;
   date            baseDate = systemDateGet();
    ;
    toDate      = dateStartMth(baseDate) - 1;
    fromDate    = dateStartMth(toDate);
    info(strFmt("%1 - %2", fromDate, toDate));
}

UtcDateTime version of the same job
static void EP_UtcdateMonthInterval(Args _args)
{
    UtcDateTime     fromDate;
    UtcDateTime     toDate;
    UtcDateTime     baseDate = DateTimeUtil::utcNow();
    ;
    // Remove this month number of days.
    toDate = DateTimeUtil::addDays(baseDate,-(DateTimeUtil::day(baseDate) -1));
    // Add the rest of this days time minus one second.
    toDate = DateTimeUtil::addSeconds(toDate, -(DateTimeUtil::time(toDate)+1));
    // Remove the number of days we are on in
    // the previous month and add one second to
    // get to the first of the month.
    fromDate = DateTimeUtil::addSeconds(DateTimeUtil::addDays(
    toDate, -(DateTimeUtil::day(toDate))), 1);
    info(strFmt("%1 - %2", fromDate, toDate));
}

When working with dates for a range in a SQL select statement, you may be in need for the first and the last day of a certain month.  What at first seems a bit difficult to calculate (not all the months have the same number of days for example), is pretty easy to accomplish with the right tools.
The first day of a month
You can fool around with things like mkdate, so something like this:
static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;

   FirstOfMth=mkdate(1,mthofyr(TransDate),year(TransDate));

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

But there is a readily available function in the Global class, albeit somewhat
hidden:DateStartMth.
So your code could read like this:
static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;
   FirstOfMth=DateStartMth(TransDate);

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

The last day of a month
Just like with the first day of a month, we have a function that will do the
job for us: endmth
This function calculates the last date in the month of the date specified.
static void LastOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate LastOfMth;
   ;

   LastOfMth=endmth(TransDate);

   info(date2str(LastOfMth,123,2,2,2,2,4));

}

Tuesday, 20 August 2013

job for normal calendar to hijri calendar conversion

static str NormaltoHijriDate(date _transDate)
{

TransDate dt;
int HijriDt;
int HijriMonth;
str Yr,finaldate;
int findate;
CalendarConverter CalendarConverter;
str Hijridat,HijriMnth,HijriYr;
;

dt = _transDate;
CalendarConverter = new CalendarConverter(PreferredCalendar::Hijri);
HijriDt = CalendarConverter.dayofmth(dt);
HijriMonth = CalendarConverter.mthofyr(dt);
Yr = CalendarConverter.yearStr(dt);

Hijridat = int2str(HijriDt);
HijriMnth = int2str(HijriMonth);
HijriYr = subStr(Yr,1,5);// Sub string is taken as i want to return only two digits of year you write as subStr(Yr,3,5);
//finaldate = HijriYr+" " +HijriMnth+" " +Hijridat;
finaldate        = Hijridat+"-"+HijriMnth+"-"+HijriYr;
return finaldate;
}

Georgian date to hijri date conversion:

Georgian date to hijri date conversion:

Before that you have to write the new method in global class and call the this method through global class
static void Job15(Args _args)
{
    date d;
    str a,k;
    str b;
    d=today();
    
    /*a= date2str(d,321,DateDay::Digits2,
        DateSeparator::Hyphen, // separator1
        DateMonth::Digits2,
        DateSeparator::Hyphen, // separator2
        DateYear::Digits4);*/
b= Global::NormaltoHijriDate(d);
    print b;
    pause;
}


Main code which you have to write new method in global class as:
static str NormaltoHijriDate(date _transDate)
{

TransDate dt;
int HijriDt;
int HijriMonth;
str Yr,finaldate;
int findate;
CalendarConverter CalendarConverter;
str Hijridat,HijriMnth,HijriYr;
;

dt = _transDate;
CalendarConverter = new CalendarConverter(PreferredCalendar::Hijri);
HijriDt = CalendarConverter.dayofmth(dt);
HijriMonth = CalendarConverter.mthofyr(dt);
Yr = CalendarConverter.yearStr(dt);

Hijridat = int2str(HijriDt);
HijriMnth = int2str(HijriMonth);
HijriYr = subStr(Yr,1,5);// Sub string is taken as i want to return only two digits of year you write as subStr(Yr,3,5);
//finaldate = HijriYr+" " +HijriMnth+" " +Hijridat;
finaldate        = Hijridat+"/"+HijriMnth+"/"+HijriYr;
return finaldate;
}

Date2str function:
1) strFmt("%1", myDate)) 
2) date2Str(dateType, 123, -1, -1, -1, -1, -1, -1) this will use the users 
regional settings which can be different between users. 
3) Most flexible way date2Str(dateType, 123, DateDay::Digits2, 
DateSeparator::Slash, DateMonth::Digits2, DateSeparator::Slash, 
DateYear::Digits4), change the enum values to your preferred format. Have a 
look here: http://msdn.microsoft.com/en-us/library/aa857241.aspx.


Example:
void DateTStringConvert()
{
date today=today();
str TodayDate;
;
 TodayDate = date2str( today,321,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4);
info(TodayDate );
}
 Note :
 The function date2str  take following parameters :
1- the date .
2- the date style dmy or ymd or....etc .
3- number of digits for day .
4- separator 
5- number of digits for month.
6- separator
7- number of digits for year.

now you can use the date as string

example:

static void date2StrExample(Args _arg)
{
date d = today();
str s;
;
s = date2Str(d, 123, 2, -1, 2, -1, 2);
print "Today's date is " + s;
pause;
} 

Thursday, 25 July 2013

Date difference calculation

c = DateTimeUtil::getDifference(_CaseDetailBase.ClosedDateTime,
                                _CaseDetailBase.createdDateTime);


CaseTimeTmp.TotalTime = c/(24*60*60);

Monday, 22 July 2013

job for date difference

static void Job7(Args _args)
{

    CaseDetail CaseDetail;
    CaseDetailBase CaseDetailBase;
    int64 a,b;
    utcDateTime c,d,e;
   
    select CaseDetail where CaseDetail.CaseId == "00004_1002";
   { d = CaseDetail.SLALatestCompletionDateTime;
       e = CaseDetail.serviceLevelAgreementStartDateTime();
       info(strfmt("%1" ,d));
       info(strfmt("%1" ,e));

    }
     a=  DateTimeUtil::getDifference(d,e);
    b= a/(24*60*60);
    info(strfmt("%1" ,a));
   
     info(strfmt("%1" ,b));
}

Tuesday, 16 July 2013

Dialog(date of birth and name)

static void Simple_Dialog(Args _args)
{
DialogButton dialogButton;
dialog dialog;
dialogGroup dialogGroup;
dialogField dialogField1;
dialogField dialogField2;
container nameAndDOB,a;
   
dialog = new Dialog(“Date and Name”);
dialogGroup = dialog.addGroup(“Enter details”);
dialogField1 = dialog.addField(extendedTypeStr(Name));
dialogField2 = dialog.addField(extendedTypeStr(TransDate));
  
if (dialog.run())
{
print dialogField1.value();
print dialogField2.value();
  nameAndDOB = [dialogField1.value(),dialogField2.value()];
pause;
}
dialogButton = Box::yesNo(“Do you want to see the birthdate?”, DialogButton::Yes);
if (dialogButton == DialogButton::Yes)
{
Box::info(strFmt(“%1, %2″, conPeek(nameAndDOB,1),conPeek(nameAndDOB,2)));
}
else
{
Box::info(strFmt(“%1″,conPeek(nameAndDOB,1)));
}
}