Solved

How to parse DATE into integers for year/month/day

Posted on 2008-10-27
2
1,364 Views
Last Modified: 2013-12-14
in C++ I get/set a timestamp from the database into a variable of DATE type (which is a double). I need a way to get year/month/day as integers from that date without using MFC! (I have an ATL-type of project, no support for MFC).
I would appreciate if someone can provide a working example and an explanation for that problem.

Thanks in advance!
0
Comment
Question by:Klava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 250 total points
ID: 22815088
Check out the VariantTimeToSystemTime() api, this converts a DATE double to a SYSTEMTIME structure, which has fields for year, month, and day.

double myDate = 2.5; // 1/1/1900 at noon
SYSTEMTIME mySysTime;

::VariantTimeToSystemTime(myDate, &mySysTime);

int year = mySysTime.wYear;

etc.
0
 

Author Closing Comment

by:Klava
ID: 31510414
thanks again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question