rahulsk19471

good day, i wanted to know how to use date and time in C++

Can some one share and tell me to handle dates and time in C++

Thanking you alot.
Rahul


Re: Visual C++ Language C++ date and time

Marius Bancila

Take a look here and here.




Re: Visual C++ Language C++ date and time

rahulsk19471

ACTUALLY, i was writing a program in C++, and trying to have 2dates in the format of (dd/mm/yy). And wanted to find the number of days between them.

I looked at the 2 links above and couldn't understand much.
If some-one has a example,that would be great if you could share.

Thanks.


Rahul SK
__________________
a beginnering to C++




Re: Visual C++ Language C++ date and time

Bite Qiu - MSFT

rahulsk19471 wrote:
ACTUALLY, i was writing a program in C++, and trying to have 2dates in the format of (dd/mm/yy). And wanted to find the number of days between them.

I looked at the 2 links above and couldn't understand much.
If some-one has a example,that would be great if you could share.

Hi Rahul,

Alternatively you can use System:: DateTime and System:: DateSpan, here is the sample code:

Code Snippet

using namespace System;

int main(){

DateTime dt1 = DateTime::Now;
DateTime^ dt2 = gcnew DateTime(1985,7,6);
TimeSpan ts = dt1.Subtract(*dt2);
Console::WriteLine(ts.Days);

return 0;
}

Have a nice day

Rico






Re: Visual C++ Language C++ date and time

Simple Samples

The C runtime has many functions that can help and C++ does not provide much more than that. There are a few different formats for dates and times supported by C. You can convert the dates to a format that makes date arithmetic easy.

See functions mktime and difftime; they might do what you need. Their names say time but they can be used for dates and times.