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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

C# code to convert string to date without time

(1) ShareShare
ReportReport
Posted on by 342

below is the code i want write web page field value i.e txtBoxDateInteraction.Text to CRM field service_dateinteraction.

ServiceA1["service_dateinteraction"] = txtBoxDateInteraction.Text;

service_dateinteraction is date field in CRM

txtBoxDateInteraction.Text consist of date value in "mm/dd/yyyy" format

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mohan Kumar  Profile Picture
    90 on at
    RE: C# code to convert string to date without time

    This works for me. Cheers!

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: C# code to convert string to date without time

    Hi Sandy,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Sandy Hello Profile Picture
    342 on at
    RE: C# code to convert string to date without time

    thanks Francesco this code ServiceA1["service_dateinteraction"] = DateTime.ParseExact(txtBoxDateInteraction.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);

    is working

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: C# code to convert string to date without time

    You can use the toShortDateString() method to convert a date time to a string in the m/d/yyyy format.

    DateTime now = DateTime.Now;

    string dateTimeString = now.ToShortDateString();

    If that doesn't work, the best recommendation to format it to your needs is using cultureInfo.

    See following Microsoft documentation on Date Time String Formats:

    docs.microsoft.com/.../standard-date-and-time-format-strings

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: C# code to convert string to date without time

    Hi Sandy,

    please update your code as follows:

    ServiceA1["service_dateinteraction"] = DateTime.ParseExact(txtBoxDateInteraction.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at
    RE: C# code to convert string to date without time

    convert it to using ServiceA1["service_dateinteraction"] =Convert.ToDateTime(txtBoxDateInteraction.Text);

    by default it will take time 12:00 AM. you can not remove it in date time field. if you are using date field it will store date time with default time 12:00 AM.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans