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

Announcements

News and Announcements icon
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
    ARIFNIIT Profile Picture
    1,391 on at

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    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
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    Sandy Hello Profile Picture
    342 on at

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

    is working

  • Suggested answer
    Community Member Profile Picture
    on at

    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
    Mohan Kumar Profile Picture
    90 on at

    This works for me. Cheers!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans