Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date to String

Status
Not open for further replies.

cpagano

Technical User
Mar 14, 2008
12
0
0
US

Please forgive this question..
I do not use C at all and need to do something for work

I have date of birth information in three fields
Year, Month and Day

I need to concatenate them to a string ddmmyy

Nothing is working for me at this time
THANKS
 
Are Year, Month & Day strings or numbers?
Should ddmmyy really use a 2-digit year? That's just asking for trouble.

Assuming Year, Month & Day are 2-digit numeric strings, just do this:
Code:
std::string date = Day + Month + Year;
// or this:
std::string date = Day;
date += Month;
date += Year;
 
thanks but what Im doing in in an interface engine and need to look something like..

out.date = in.day + in.month + in.year

However this adds the values to a number

As for your question..
Are Year, Month & Day strings or numbers? Numbers
I think it does need a four digit year and
Should ddmmyy really use a 2-digit year? probably you are right 4 YYYY

Thanks
 
What data type is out.date? I'd guess that in.month, in.day, and in.year are int data types. Is that correct?

Lee
 
Then you could do something like this:
Code:
std::stringstream ss;
ss << in.day << in.month << in.year;
ss >> out.date;
 
If you do not want a purely C++ answer, have a look at strftime.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top