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

  • SEARCH
  • Home
  • 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 6749669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:04+00:00 2026-05-26T12:43:04+00:00

Coming from C# it was quite common for me to write a class that

  • 0

Coming from C# it was quite common for me to write a class that might have a DateTime as a return type (or parameter). Now I’m programming in C++. What is the appropriate data type to use as a method return value returning a datetime value (time_t, tm struct, Boost.Date_Time, something else?) E.g.:

class Customer
{
   ...
   ? GetDateTimeCreated() const;
   void SetLastContactDateTime(? date);
   ...
}

Also, what about accepting date/times as function parameters?

  • 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-05-26T12:43:04+00:00Added an answer on May 26, 2026 at 12:43 pm

    If you’re writing a library, and the datetime value will exposed via the API, then I’d use time_t so that users of the library are not forced to use Boost.

    As was pointed out, struct tm is used for formatting a time_t. You don’t normally want to be passing those around.

    If your program already uses Boost, and you like the convenience of Boost.DateTime, then by all means use Boost.DateTime. If I remember correctly, boost::posix_time::ptime is just a wrapper around two 64-bit integers, so it’s lightweight enough to pass around by value.

    If you’re using C++11 features, then you might want to use std::chrono::time_point from <chrono>. If you’re still on C++03, you can use Boost.Chrono, which aims to implement the C++11 time facilities. By using Boost.Chrono, you should be able to more easily make the switch to C++11 in the future. Chrono doesn’t have as many features as Boost.DateTime, but it’s a step up from plain old time_t.

    If you need sub-second precision, then Boost.DateTime or Chrono is the way to go.

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

Sidebar

Related Questions

I'm new to JScript coming from a C++ world. I'm quite surprised that expressions
Coming from C++, I find generic programming indispensable. I wonder how people approach that
I have denormalized data (coming from a file) that needs to be imported into
I have been using Python for about a year now, coming from a mostly
I'm new to MVC3 coming from CakePHP, and have been quite impressed. But I've
Coming from a corporate IT environment, the standard was always creating a class library
Coming from a background, I'm familiar with GUI editors that do a poor job
Coming from a Perl background, I have to say I prefer cpan Foo::Bar to
This question is not coming from a programmer. (obviously) I currently have a programmer
I am new to web programming, coming from a video game development background (c++),

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.