Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Date to String

Date to String

Date to String


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

RE: Date to String

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:


std::string date = Day + Month + Year;
// or this:
std::string date = Day;
date += Month;
date += Year;

RE: Date to String

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


RE: Date to String

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


RE: Date to String

out is string
in is int

RE: Date to String

Then you could do something like this:


std::stringstream ss;
ss << in.day << in.month << in.year;
ss >> out.date;

RE: Date to String

thanks, Ill try it

RE: Date to String

If you do not want a purely C++ answer, have a look at strftime.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close