Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:43:05+00:00 2026-06-04T16:43:05+00:00

I have the following date : std::string sdt(2011-01-03); I wrote 2 functions as below

  • 0

I have the following date :

std::string sdt("2011-01-03");

I wrote 2 functions as below and called them using:

 date test;
  string_to_date(sdt,test);
  date_to_string(test,sdt);

the string_to_date() works and it returns
2011-Jan-03 as it should
whereas the date_to_string() returns

not-a-date-time

these are the functions:

void string_to_date(const std::string& st, date out)
{
  std::string in=st.substr(0,10);
  date d1(from_simple_string(std::string (in.begin(), in.end())));
  std::cout<<d1;
  out=d1;
}


void date_to_string(date in, const std::string& out)
{

  date_facet* facet(new date_facet("%Y-%m-%d"));
  std::cout.imbue(std::locale(std::cout.getloc(), facet));
  std::cout<<in<<std::endl;

    out=in;//this doesn't work

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:43:06+00:00Added an answer on June 4, 2026 at 4:43 pm
    void date_to_string(date in, std::string& out)
    {
        std::ostringstream str;
        date_facet* facet(new date_facet("%Y-%m-%d"));
        str.imbue(std::locale(str.getloc(), facet));
        str << in;
    
        out = str.str();
    }
    

    should work. Notice the removed const from the out parameter. Is there a reason not to simply return the produced string?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following date as string 091020. I am using SubSonic as my
I have the following date in string format 2011-29-01 12:00 am . Now I
I have the following date string: 2011-09-06T22:02:57-04:00 . The problem is the timezone, -04:00
i have following code #include <iostream> #include <string> using namespace std; string generate(){ for
Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
I have the following code: #include <iostream> using namespace std; struct stud{ int roll;
I have the following date stored as a string 04.09.2009 (dd.mm.yyyy) Now I would
I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
I'm trying to convert a timestamp string to Date in PHP. I have following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.