Solved

Type Conversion, CString to longbinaray, CString to datetime

Posted on 1997-11-02
2
622 Views
Last Modified: 2013-11-20
hello,
   i'd like to know how can i convert CString to longbinary... and also CString to datetime... thanks, :) mallow
0
Comment
Question by:mallow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 20 total points
ID: 1309168
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);


0
 

Expert Comment

by:mmachie
ID: 1309169
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.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question