ATL Date Routines

Environment: Visual C++ 6 (SP3)

When writing ATL components, one of the hardest things to overcome for Windows programmers, in my opinion, is the dependency on the MFC library. For dates and strings, MFC simplifies the programmer’s job by handling memory allocations and type conversions within its class encapsulation. However, with that simplification comes the price of having to distribute the MFC DLL’s with your component.

This article focuses on the issues surrounding the use of dates within an ATL component. I developed the DateLib component as part of a project for my company and, as such, the methods of this component are specific to my company’s requirements (I do not have an intellectual property agreement with this company). However, the DateLib component does illustrate how to build an ATL component that has no MFC dependencies, is thread-safe, and will compile as either ANSI or UNICODE.

The methods within the DateLib component are as follows:

Date Formatting Routines

  • Now - Returns the current system date in a DATE variable.
  • OLE2Oracle - For a given DATE, returns a formatted string using the DD-Mon-YYYY representation.
  • Int2Oracle - For a given month, day, and year, returns a formatted string using the DD-Mon-YYYY representation.
  • Int2OLE - For a given month, day, and year, returns the date in a DATE variable.
  • OLE2String - For a given DATE, returns a formatted string using the MM/DD/YYYY representation.

Date Parsing Routines

  • ParseOracle2OLE - For a given date given in a M/D/YY format, returns the date in a DATE variable.
  • ParseOracle2String - For a given date given in a M/D/YY format, returns a formatted string using the MM/DD/YYYY representation.
  • ParseOracle2Oracle - For a given date given in a M/D/YY format, returns a formatted string using the DD-Mon-YYYY representation.

Date Math Routines

  • GetFirstDay - For a given DATE, returns the first day of the month in a DATE variable.
  • GetLastDay - For a given DATE, returns the last day of the month in a DATE variable.
  • GetNextDay - For a given DATE, returns the next day’s date in a DATE variable.
  • GetNextWeek - For a given DATE, returns the next week’s date in a DATE variable.
  • GetNextMonth - For a given DATE, returns the next month’s date in a DATE variable.
  • GetNextYear - For a given DATE, returns the next year’s date in a DATE variable.
  • GetPreviousDay - For a given DATE, returns the previous day’s date in a DATE variable.
  • GetPreviousWeek - For a given DATE, returns the previous week’s date in a DATE variable.
  • GetPreviousMonth - For a given DATE, returns the previous month’s date in a DATE variable.
  • GetPreviousYear - For a given DATE, returns the previous year’s date in a DATE variable.

Downloads

Download demo project - 4 Kb
Download source - 31 Kb


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds