We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Type Conversion, CString to longbinaray, CString to datetime

on
Medium Priority
661 Views
hello,
i'd like to know how can i convert CString to longbinary... and also CString to datetime... thanks, :) mallow
Comment
Watch Question

## View Solution Only

Commented:
By longbinary I am assuming you mean long.  That is pretty easy.

int len;
CString Num;
long ConvertedNum;
int ct;
char temp;

len = Num.GetLength();

for(ct = 0; ct < len; ++ct)
{
temp = Num.GetAt(ct);
ConvertedNum = (long)(temp + 48);
ConvertedNum *=10;
}

CString to DateTime would go something like this:

int Month;
int Year;
int Day;
int pt;
CString temp;

CString OldDate;
COleDateTime NewDate;

pt = OldDate.Find("/");
temp = OldDate.Left(pt);

//At this point use to code above for converting a CString to a long, just substitiue int for long and set Month equal to the resulting value.  Trim off the value of temp from OldDate and perform this operation twice more to get the Day and Year.  Then call COleDateTime.SetTime(M, D, Y, H, M, S);

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
to conver a cstring to a long value try:
CString num_to_convert;
long converted_num = atol( num_to_convert);

to convert the cstring to a COleDateTime you must parse out the the year, month, and day.  try using the CString::Mid() function.  convert the parsed value using atoi() function then call COleDateTime::SetDate() with the converted values.

hope this helps.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile