web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

To pass string date value into the date value in form .

(0) ShareShare
ReportReport
Posted on by 1,836
hi everyone 
i am having two dates user expiry date and user date which is string , so when the user enter the date in this two fields the both the date should be converted  pass into the calander start date and calander expire date .how can i get this done plz help me on this .
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    i want to convert the user date into by using this method , can anyone one plz guide me how can i pass user date into this method and then return the to be pass in the calander start date plz let me know i dont have any idea how to get thiss done .
    static date hijri2GrDate(DAPHijridateStr   hijriDateStr)
    {
        System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
        System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
        System.DateTime                  tempDateTime;
        str                              strTemp;
        System.String[]                  arr;
        date                             grDate;
    ;
     
        //all expected dates formats
        arr = new System.String[18]();
        
        arr.SetValue("dd/MM/yyyy",  1);
        arr.SetValue("dd-MM-yyyy",  2);
     
        try
        {
            tempDateTime = System.DateTime::ParseExact(hijriDateStr, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
        }
        catch
        {
            error("Unexpected Hirji date format.");
            return datenull();
        }
        strTemp = tempDateTime.ToString("dd/MM/yyyy");
        grDate = str2date(strTemp, 123);
     
        return grDate;
    }
     
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    I'm not sure what you need from us. Are you saying that you don't know how to refer to a field or how to call a static method?
     
    Here are some examples of field references: myBuffer.UserDate, this.UserDate. And this is a call of a static method: MyClassOrTable::hijri2GrDate().
     
    Putting it together, the call might look like this: MyDateHelperClass::hijri2GrDate(this.UserDate).
     
    By the way, what's the point of converting the string to a date, then again to string and then to date once more? Why don't you do just one conversion, from string to date? You can declare tempDateTime at utcDateTime and then extract the date part by DataTimeUtil::date().
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    martin ,
    thanks for reply ,
     i need to convert the date value to and pass it to calander date value , 
    i have override these two methods , below is my code plz correct me where i am getting wrong ,
      [Control("String")]
        class DTPropertyLine_DTHijriDate
        {
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public boolean modified()
            {
                boolean ret;
                DTHijriDate   hijriDateStr;
                ret = super();
                       
                DTPropertyLine.DTCalenderStartDate = this.hijri2GrDate(hijriDateStr);
        
                return ret;
            }
    
            /// <summary>
            ///
            /// </summary>
            //private void FormControlMethod1()
            //{
                private date hijri2GrDate(DTHijriDate   hijriDateStr)
                {
                    System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
                    System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
                    System.DateTime                  tempDateTime;
                    str                              strTemp;
                    System.String[]                  arr;
                    date                             grDate;
                    ;
     
                    //all expected dates formats
                    arr = new System.String[18]();
        
                    arr.SetValue("dd/MM/yyyy",  1);
                    arr.SetValue("dd-MM-yyyy",  2);
     
                    try
                    {
                        tempDateTime = System.DateTime::ParseExact(hijriDateStr, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
                    }
                    catch
                    {
                        error("Unexpected Hirji date format.");
                        return datenull();
                    }
                    strTemp = tempDateTime.ToString("dd/MM/yyyy");
                    grDate = str2date(strTemp, 123);
     
                    return grDate;
                }
            //}
        }
     
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Putting this business logic to a form control is a bad idea, because you couldn't call it from other places where you may need such a conversion. Use a class instead.
  • Dineshkarlekar Profile Picture
    1,836 on at
     hi martin ,
    i the user enter the hijri date it should be converted to date which i want to insert in calander start date , thats why i need to use this code . 
     
     plz correct me if i am repeating any steps in my code .like i am converting the date to string again and again  .
     
    "By the way, what's the point of converting the string to a date, then again to string and then to date once more? Why don't you do just one conversion, from string to date? You can declare tempDateTime at utcDateTime and then extract the date part by DataTimeUtil::date()."
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi martin ,
      I have made the class , code is below 
    final class DTHijri2date
    {
        static date hijri2GrDate(DTHijriDate   hijriDateStr)
        {
            System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
            System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
            System.DateTime                  tempDateTime;
            str                              strTemp;
            System.String[]                  arr;
            date                             grDate;
            ;
     
            //all expected dates formats
            arr = new System.String[18]();
        
            arr.SetValue("dd/MM/yyyy",  1);
            arr.SetValue("dd-MM-yyyy",  2);
     
            try
            {
                tempDateTime = System.DateTime::ParseExact(hijriDateStr, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
            }
            catch
            {
                error("Unexpected Hirji date format.");
                return datenull();
            }
            strTemp = tempDateTime.ToString("dd/MM/yyyy");
            grDate = str2date(strTemp, 123);
     
            return grDate;
        }
    
    }
    
     [Control("String")]
        class DTPropertyLine_DTHijriDate
        {
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public boolean modified()
            {
                boolean ret;
                DTHijriDate   hijriDateStr;
                ret = super();
                       
                DTPropertyLine.DTCalenderStartDate = DTHijri2date::hijri2GrDate(hijriDateStr);
        
                return ret;
            }
          
        }
     
    call it in my modified method , plz let me know if i am missing any thing .
  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    First of all, hijriDateStr variable will always be empty, because you never assign any value to it. I wonder how you debugged your code that you didn't notice such an obvious problem.
     
    Then you should pay more attention to where you put your logic.
     
    I'm assuming that DTPropertyLine_DTHijriDate control is bound to a data source field (DTPropertyLine.DTHijriDate). Your code suggests that the conversion should happen only for this specific form control and not to any other control bound to the same field (which may be added both by developers and users). This sounds like a bug in your design.
     
    Another possible place is a data source field, but I think it would be wrong to in this case. If the logic isn't specific to this single form, the right place is doing it on the table. The table method executed when a field changes is modifiedField().
    public void modifiedField(FieldId _fieldId)
    {
        switch (_fieldId)
        {
            case fieldNum(DTPropertyLine, DTHijriDate):
                this.DTCalenderStartDate = DTHijri2date::hijri2GrDate(this.DTHijriDate);
                break;
        }
    }
    Another option is doing it when saving the record (insert()/update()).
     
    Also, I've noticed that you still didn't throw away the extra conversions back to string and to date again. Read my first reply again if you missed the problem report.
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi martin 
    thanks for code , i tried to take value from formstringcontrol now the value is passing into method but the date is not getting converted , i have debugged the code and getting error
    "Unexpected Hirji date format." my date is not converting but i am getting the value in variable  "hijriDateStr". but in try statement its not converting the values , i have entered this value from front end 10/04/1445 to convert . and i have changed the code in modified ,method  the code is below . 
      [Control("String")]
        class DTPropertyLine_DTHijriDate
        {
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public boolean modified()
            {
                boolean ret;
                DTHijriDate   hijriDateStr;
                ret = super();
                hijriDateStr =  this.text();
                DTPropertyLine.DTCalenderStartDate = DTHijri2date::hijri2GrDate(hijriDateStr);
        
                return ret;
            }
    
        }
     
     
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Your last question isn't related to the topic of this thread, which is To pass string date value into the date value in form. It has nothing to do with a form, it's about a conversion of Hirji date 10/04/1445. Please create a new thread (with an appropriate title) and we can discuss it there. Here we'll discuss the form logic, although I suspect that there should be none (because the logic should actually be implemented on the table, as discussed below).
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    martin 
    thanks for helping me out , 
    the values are getting converted now , due to the size of array system.string[18]  there was error which i updated to system.string[2] .the values are getting inserted on rwquired fields now.
    thanks,
    Regards ,
    Dinesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans