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 :
Microsoft Dynamics CRM (Archived)

Getting Today's date using CrmDateTime

(0) ShareShare
ReportReport
Posted on by 635

Hi

I have a requirement where I have to set a field's value to Today's date using CrmDateTime.

How can I do this? I don't see any such property in the object of CrmDateTime class.

Regards

Rahul

*This post is locked for comments

I have the same question (0)
  • Jeremy Winchell Profile Picture
    1,165 on at

    Rahul,

    The CrmDateTime object is nothing more than a wrapper really around the Date object in C#.  You can do something like this:

    DateTime _today = DateTime.Today();

    CrmDateTime _crm = new CrmDateTime(_today);

    Jeremy Winchell

    Inetium

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Jeremy,

    You code would not work because CrmDateTime class doesn't have constructor which will get DateTime as parameter and Today is property of DateTime and not method.

    Rahul,

    You can use following code:

    CrmDateTime _crm = new CrmDateTime(DateTime.Today.ToString("s"));

  • Jeremy Winchell Profile Picture
    1,165 on at

    Andriy,

    Thanks for my correction, I was thinking of a different object.   Thank you for the correction in my code.  You can also use the .Now() static method of the CrmDateTime object if you don't want to use DateTime.Today.

    Jeremy

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Jeremy,

    If I'm not wrong Now is static property of CrmDateTime class.

  • Bobins Bansala Profile Picture
    95 on at

    Hi Rahul,

    you can follow the below code:

    DateTime CurrentDate = DateTime.Today;

    RecordName.Attributes["sal_startdatetime"] = StartDate;

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans