Thomas Stockbruegger
asked on
Need some help to convert CString into DATETIME
Hello,
I would like to convert a CString into DATETIME.
In my SQL Table the row Lieferscheindatum has the DATETIME format.
The user can fill 2 Editboxen with the start date and stop date.
f.e.
start date stop date
01.03.2011 04.05.2011 (f.e.todays date)
So I have 2 strings
CString start_date="01.03.2011"
CString stop_date="04.05.2011"
I tried the following...but it will not work
COleDateTime start;
start.ParseDateTime(start_ date);
COleDateTime stop;
stop.ParseDateTime(stop_da te);
sql.Format("SELECT * FROM ViewLieferscheine WHERE \
Lieferscheindatum BETWEEN %d AND %d \
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC",start,stop);
This will work....but I need the dates from the Editboxen, so I have to convert the CString
sql.Format("SELECT *FROM ViewLieferscheine
WHERE Lieferscheindatum BETWEEN '20110301' AND '20110504'\
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC");
500 points with a solution.
Please help.
Best regards,
Thomas
a.BMP
I would like to convert a CString into DATETIME.
In my SQL Table the row Lieferscheindatum has the DATETIME format.
The user can fill 2 Editboxen with the start date and stop date.
f.e.
start date stop date
01.03.2011 04.05.2011 (f.e.todays date)
So I have 2 strings
CString start_date="01.03.2011"
CString stop_date="04.05.2011"
I tried the following...but it will not work
COleDateTime start;
start.ParseDateTime(start_
COleDateTime stop;
stop.ParseDateTime(stop_da
sql.Format("SELECT * FROM ViewLieferscheine WHERE \
Lieferscheindatum BETWEEN %d AND %d \
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC",start,stop);
This will work....but I need the dates from the Editboxen, so I have to convert the CString
sql.Format("SELECT *FROM ViewLieferscheine
WHERE Lieferscheindatum BETWEEN '20110301' AND '20110504'\
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC");
500 points with a solution.
Please help.
Best regards,
Thomas
a.BMP
ASKER
I got the error ToString is not a Element of COleDateTime
framing the query like this may help:-
SELECT * FROM ViewLieferscheine
WHERE Lieferscheindatum BETWEEN convert(datetime,'01.03.2011',103) AND
convert(datetime,'04.05.2011',103)
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC
Use .Format instead of .ToString
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes....thank you convert will work, here is the complete solution
CString start="01.03.2011";
CString stop="01.04.2011";
sql.Format("SELECT * FROM ViewLieferscheine WHERE \
Lieferscheindatum BETWEEN CONVERT (datetime,'%s',103) AND
CONVERT(datetime,'%s',103) \
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC",start,stop);
CString start="01.03.2011";
CString stop="01.04.2011";
sql.Format("SELECT * FROM ViewLieferscheine WHERE \
Lieferscheindatum BETWEEN CONVERT (datetime,'%s',103) AND
CONVERT(datetime,'%s',103)
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC",start,stop);
ASKER
thank you for your help
sql.Format("SELECT * FROM ViewLieferscheine WHERE
Lieferscheindatum BETWEEN {0} AND {1} \
ORDER BY CAST(LieferscheinNr AS BIGINT)DESC",start.ToStrin
Thanks