YaelS

How can I compliet to zero if I have 14:3 --> 14:03

from these I get sNewMinute = "";

//sNewMinute.Format(minute, "%M");

//sNewMinute.Format(minute, "00");




Re: Visual C++ General CString format

Johan Levin

CString::Format works like printf.

Code Snippet

CString str;

str.Format(_T("%02d"), 3);

// str is now "03".


It appears you're formatting times. If you have the time as a CTime, then you can use the formatting I described in your SQL query thread yesterday.

- J





Re: Visual C++ General CString format

YaelS

1) Maybe you could tell me how can I add 1 day to CTime

deu_date befor = 115362002

after I add 1 = 115362003

I neet to set 1 to 215362002

//CTime deu_date;

deu_date += 1;

Code Snippet






Re: Visual C++ General CString format

Johan Levin

I think I'd try this code:

Code Snippet

int hour, minute;

_stscanf_s(task_time, _T("%d:%d"), &hour, &minute);

CTimeSpan timeSpan(0, 0, hour, minute, 0);

timeSpan += CTimeSpan(0, 0, 5, 0);

this->task_time = timeSpan.Format(_T("%H:%M"));


By the way, have you tried what your code would do with the time "9:23" It would parse it as hour 9 and minute 3.

- J





Re: Visual C++ General CString format

YaelS

mmm..

It's work in this code:

int pos = this->task_time.Find( ':' );

CString sTimeH = this->task_time.Left(pos);

CString sTimeM = this->task_time.Right(pos);

// convert minutes & hours to long

long minute = atol(sTimeM);

long hour = atol(sTimeH);

// ...my add code...

CTimeSpan timeSpan(0, hour, minute, 0);

this->task_time = timeSpan.Format(_T("%H:%M"));

You could tell me how can I add 1 day to CTime

deu_date befor = 115362002

after I add 1 = 115362003

I neet to set 1 to 215362002

//CTime deu_date;

deu_date += 1;






Re: Visual C++ General CString format

Johan Levin

You can add one day just like I added 5 minutes above.
+= CTimeSpan(1,0,0,0);

But you still have the bug with "9:23" being interpreted as 09:03.
pos = 1;
sTimeH="9";
sTimeM="3"; // Since task_time.Right(1) takes only the rightmost character.

Consider using sscanf.





Re: Visual C++ General CString format

YaelS

I'm Ok!