• Events & Webinars
  • Resources
    • Blog
    • Case Studies
    • News
    • Newsletter
    • Infographics
    • Papers
    • Posters
    • Video
  • Careers
    • Careers at HBS
    • Open Positions
    • Student Opportunities
  • About HBS
    • About Us
    • Leadership
    • Locations
    • Partners
    • Green Initiatives
  • Events & Webinars
  • Resources
    • Blog
    • Case Studies
    • News
    • Newsletter
    • Infographics
    • Papers
    • Posters
    • Video
  • Careers
    • Careers at HBS
    • Open Positions
    • Student Opportunities
  • About HBS
    • About Us
    • Leadership
    • Locations
    • Partners
    • Green Initiatives
HBS logo
HBS Logo
  • Infrastructure
    • CLOUD

      • Cloud Solutions
      • Public Cloud
      • Hybrid Cloud
      • Infrastructure as a Service
      • Cloud Security Solutions
      • Backup, Replication and Disaster Recovery
      • HBS Cloud Hosting Services

      DATA CENTER

      • Data Center Solutions
      • Traditional Data Center
      • Hyperconverged
      • Colocation
      • Directory Services
      • Cloud Email and Calendar Solutions

      NETWORK AND ACCESS

      • Network Infrastructure
      • Enterprise Mobility
      • Wireless Solutions
      • SD-WAN
      • Structured Cabling
      • Staff Augmentation
  • Managed Services
    • MANAGED ONE

      • Managed One Overview
      • Managed Backup and Disaster Recovery
      • Managed Email and Collaboration Security
      • Managed Firewall

       

      • Managed HaaS and SaaS
      • Managed IT Help Desk
      • Managed Network and Server Monitoring

      HBS + PARTNER SOLUTIONS

      • HBS Secure with Verkada
      • HBS Collaborate with Webex
      • Managed XDR
      HBS Managed One Megamenu Graphic
  • Modern Workplace
    • MICROSOFT

      • Microsoft Licensing Management
      • Microsoft Modern Workplace
      • Microsoft Fabric

       

      • Dynamics 365 Business Central
      • Dynamics 365
      • Dynamics GP

      COLLABORATION

      • Audio Visual
      • Unified Communication Solutions
      • HBS Collaborate with Webex
  • Professional Services
    • ADVISORY

      • Virtual CISO
      • Virtual CIO
      • Project Management
      • IT Business Consulting

      ENGINEERING SERVICES

      • Staff Augmentation

      AI & ANALYTICS

      • Artificial Intelligence
      • AI Advance
      • AI Predict
      • AI Assist
      • Data Management and Analytics
      • Microsoft Fabric

      APPLICATION INNOVATION

      • Website Development
      • Application Development

      DOCUMENT MANAGEMENT

      • Document Management Services
      • Document and Check Scanners
  • Security
    • CYBERSECURITY

      • Managed XDR
      • Penetration Testing
      • Vulnerability Scanning
      • Email Security Services
      • Digital Forensics and Incident Response
      • Backup, Replication and Disaster Recovery
      • Firewalls
      • Cloud Security Solutions

       

      • Virtual CISO
      • Virtual Security Team
      • Virtual Security Engineer
      • Cybersecurity Risk Assessment
      • Governance and Compliance
      • SOC 2
      • CMMC
      • Managed Security Awareness Training

      PHYSICAL SECURITY

      • Security Solutions
      • HBS Secure with Verkada
      Cybersecurity Risk Assessment Megamenu Graphic
  • Search
Contact Us
Blog

Addressing Common Challenges with Dates in Dynamics 365

  • Written by: Drew Poggemann
  • November 27, 2018
Dynamics 365 xRM Feature Image

Defaulting Date to Today()

Common issue: "How can I default a date on a form (i.e. a submit date) to today's date?"

Use Real-Time Workflow

Implement a real-time workflow that fires on the creation of the entity. The workflow will set a date field on the entity to the process should pull the dynamic value of the process date and set a date field on the entity. When the record is saved the field will be populated.

Account Information Summary Image

One challenge of this approach is the field is not populated until the record is saved.

Use Custom Code

Another way to set a field on the form and have it populated on initial form load is through a JavaScript resource that will fire on the OnLoad event of the form. The JavaScript function would be fairly simple and straight-forward.

Xrm.Page.getAttribute("new_currentdate").setValue(Date.now());

Remember, if you only want to set this if blank, you will want to wrap this with an if statement so it is not reset every time the form is opened...

if (Xrm.Page.getAttribute("new_currentdate").getValue() !== null) { 
   Xrm.Page.getAttribute("new_currentdate").setValue(Date.now());}

Calculating Age

Common Issue: How do I calculate the age of someone in Dynamics 365?
Calculating age in Dynamics 365 has been something I have seen in a number of posts over the years. Overall, the general approach appears to calculate the days between two dates and then dividing this by 365 to get the age in years. Example, you could use a calculated field that will have a formula like:

DIFFINDAYS(new_DOB, NOW()) / 365>

Now, this will work in many situations but it will not work correctly with handling leap years so if you are born anywhere close to February 28th this will probably not provide a correct answer. Leap years are tricky: A leap year is every 4 years, but not every 100 years, then again every 400 years. To address this leap year challenge, I did the following:

  1. Created a birthday field that was date and time, this is required for the calculations, date only did not work.
  2. Created an Age field that was a Decimal format with 7 decimal places to address rounding because some of the values get very close and you don't want it to round up or down.

Calculation in Age calculated field:

(DiffInDays(new_birthday, now()) - (DiffInYears(new_birthday, now()) / 4)) / 365

This calculation will work for anyone born after the year 1900 and it will work through the year 2099 as the divide by 4 will not work after that date :) If you are trying to future-proof the past that then you will need to add more to the calculation but I expect this will work for most situations.

Dates in Workflow

Many times I find myself needing to manipulate dates in workflows. This could be setting a follow-up date, calculating how many days something has been open, adding a number of business days to another date value, etc. The best tool I have found for this and utilize all the time is MVP Jason Lattimer's date and time utilities. This toolset has helped me numerous times to accomplish date manipulation in workflows that I would not have been able to accomplish without custom workflow activities otherwise.

SSRS Date Example

Returning records in date ranges in SSRS reports is a common reporting type of need in the forums, especially when it comes to a date range compared to the current date. The following is an example response I provided to a question around returning the past 12 months of records related to a specific date on an entity. Hopefully this is helpful for anyone with a similar challenge.

ah.accountdate >= DATEADD(month, -12, DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)) 
AND ah.accountdate < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)

Related Content

Dynamics GP vs Dynamics 365 Business Cenrtral

Dynamics GP vs Dynamics Business Central

Compare Microsoft Dynamics GP and Business Central. Discover differences in pricing, deployment, AI, and future support.

Learn More »

Developing an Adaptable Dynamics 365 and Power Apps Solution with Rose Paving

Rose Paving, a national pavement contractor, was looking for a partner to assist them in transforming their communication system with their multiple satellite offices. 

Explore More »
Dynamics 365 Business Central Gudie

Get to Know Dynamics 365 Business Central

Discover how Microsoft Business Central helps businesses connect financials, operations, sales, and service in one cloud-based ERP.

Read More »
  • Dynamics 365, Microsoft
Blog

Connect:

[email protected]  |  800.236.7914

HBS logo

HQ | 1700 Stephen Street
Little Chute, WI 54140
Locations

HBS Remote Support | Service & Technical Support | E-Bill Portal
Terms & Conditions | Cookie Policy | Privacy Policy | Onboarding Form | End User Agreements | E-Bill FAQ | Site Map
©2026 Heartland Business Systems. All rights reserved.

Halo from HBS
This chat may be recorded as described in our Privacy Policy.