Solved

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

Posted on 2008-10-27
2
1,352 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now