Click here to Skip to main content
13,900,869 members
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 16 Nov 1999

Date-Time Conversion Utility

, 21 Sep 2001
Rate this:
Please Sign up or sign in to vote.
A simple app that converts to and between time_t, DATE, and regular date string expressions

Sample Image


Lately, I've had to do a lot of work with CTime and COleDateTime object variables. They're pretty nice classes to work with but not when you're debugging and need to know their actual date-time values. The CTime class stores its value in a time_t member variable and COleDateTime uses the DATE type to keep its value. Unfortunately, when we need to know what they mean in human-readable format, such as 11/03/1999 14:08:56, it's not possible without explicitly writing some code to format them into a string. Well, I got tired of writing such code so instead I wrote a little application where I could input the value I need to figure out and then have it converted at the click of a button. The application is called DTConverter and it's a simple MFC dialog-based application that allows you to convert to and from a time_t, a DATE, or a regular string in %m/%d/%Y %H:%M:%S format.

I hope it makes debugging your date-time objects less painful. Enjoy it!

Update by Geert Delmeiren

I use COleDateTimeSpan variables. These are also non-human readable, so I extended the utility for converting COleDateTimeSpans also.

For converting a variable, a couple of mouse clicks are needed:

  1. Ctrl-C to copy the variable's value
  2. Click on the utility's session in the task bar
  3. Click in the edit field you want to paste
  4. Ctrl-V to paste the value
  5. Click on the <convert> button to convert the value

That could be quicker! So I extended the utility with (configurable) auto-paste/auto-convert functionality. In the fully automatic mode steps 3) to 5) are obsolete. You just copy the value and activate the utility and... there's the result!

Another small change: The human readable date/time string now uses the format specified in the regional settings.


  • 22nd September, 2001 - Added 'Always on Top' and disabling GUI logic to the dialogs


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Alvaro Mendez
Web Developer
United States United States
I've done extensive work with C++, MFC, COM, and ATL on the Windows side. On the Web side, I've worked with VB, ASP, JavaScript, and COM+. I've also been involved with server-side Java, which includes JSP, Servlets, and EJB, and more recently with ASP.NET/C#.

You may also be interested in...

Comments and Discussions

QuestionGreat article Pin
Michael Haephrati13-Jul-14 10:05
mvpMichael Haephrati13-Jul-14 10:05 
QuestionHow to find 3rd friday date in every month in every year Pin
tns_ranjith26-Mar-08 19:24
membertns_ranjith26-Mar-08 19:24 
Generalits good stuff Pin
sri sankaradoss20-Jun-07 9:19
membersri sankaradoss20-Jun-07 9:19 
GeneralNice demo Pin
tommyplus225-Oct-06 17:51
membertommyplus225-Oct-06 17:51 
GeneralConvert CString to CTime / COleDateTime Pin
P-Rex14-Jun-05 4:36
memberP-Rex14-Jun-05 4:36 
GeneralRe: Convert CString to CTime / COleDateTime Pin
Alvaro Mendez15-Jun-05 14:35
memberAlvaro Mendez15-Jun-05 14:35 
GeneralRe: Convert CString to CTime / COleDateTime Pin
Wietsie28-Jun-05 7:59
sussWietsie28-Jun-05 7:59 
GeneralRe: Convert CString to CTime / COleDateTime Pin
Anonymous28-Jun-05 7:52
memberAnonymous28-Jun-05 7:52 
QuestionRe: Convert CString to CTime / COleDateTime Pin
David Crow4-Aug-06 4:23
memberDavid Crow4-Aug-06 4:23 
GeneralyGood job! Pin
Anonymous10-Mar-05 10:03
memberAnonymous10-Mar-05 10:03 
QuestionCDate function in C#??? Pin
Qamarwis19-Jan-04 9:19
memberQamarwis19-Jan-04 9:19 
AnswerRe: CDate function in C#??? Pin
Alvaro Mendez19-Jan-04 10:06
memberAlvaro Mendez19-Jan-04 10:06 
GeneralDATE problem Pin
anirban maiti4-Jun-03 20:55
memberanirban maiti4-Jun-03 20:55 
GeneralCString to DateTime Pin
Komtiki11-Apr-02 7:38
memberKomtiki11-Apr-02 7:38 
GeneralRe: CString to DateTime Pin
KarstenK29-Apr-02 3:09
mveKarstenK29-Apr-02 3:09 
GeneralRe: CString to DateTime Pin
Komtiki29-Apr-02 18:27
memberKomtiki29-Apr-02 18:27 
GeneralRe: CString to DateTime Pin
Vandana G25-Jul-02 13:16
sussVandana G25-Jul-02 13:16 
GeneralRe: CString to DateTime Pin
Vandana G25-Jul-02 13:17
sussVandana G25-Jul-02 13:17 
CString x ="1/1/2001 10:12:12";

int m, d, Y, H, M, S;
sscanf(x, "%d/%d/%d %d:%d:%d", &m, &d, &Y, &H, &M, &S);

CTime t(Y, m, d, H, M, S);

GeneralRe: CString to DateTime Pin
Gordon D.Marcus15-Apr-03 20:46
memberGordon D.Marcus15-Apr-03 20:46 
GeneralAlternative method Pin
24-Sep-01 16:33
suss24-Sep-01 16:33 
GeneralRe: Alternative method Pin
Marcello4-Mar-02 19:26
memberMarcello4-Mar-02 19:26 
GeneralRe: Alternative method Pin
mwilliamson4-Aug-03 16:36
membermwilliamson4-Aug-03 16:36 
GeneralCOleDateTimeSpan flaw Pin
14-Aug-01 4:23
suss14-Aug-01 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190306.1 | Last Updated 22 Sep 2001
Article Copyright 1999 by Alvaro Mendez
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid