请教关于VC++中关于对话框的小问题?

pudding 2002-03-14 09:17:52
我在对话框中使用了一个“日期控件”,定义为CTime类型变量,又使用了一个“列表控件”,列表控件中的一个列为“日期”。定义一个数据库表,其中一列为“日期”,它从“日期控件”中得到用户的输入值。对话框为用户提供查询功能。用户查询时,在“日期控件”中输入“日期”作为查询条件,我将此“日期”值存入CRecordset类的m_strFilter中,从数据库中得到相应记录,显示在“列表控件”中。
程序编译时,提示“CTime”类型不能转换成“CString”类型(在m_strFilter中用作查询条件时),请问我该怎么办?另外还有int类型与CString类型之间的转换问题。谢谢!
...全文
75 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pudding 2002-03-20
  • 打赏
  • 举报
回复
这个问题我还是没能解决!
pudding 2002-03-16
  • 打赏
  • 举报
回复
帮帮忙!
pudding 2002-03-15
  • 打赏
  • 举报
回复
我用CTime定义了时间控件对应的变量
CTime date;
CRecord * m_set;(CRecord 中有对应数据库表中列的变量m_date,表中列定义为Datetime类型;

//赋值
m_set->m_date=date;
UpdateData(TRUE);

结果数据库表中得到的列date的值不仅有年、月、日,还有时、分、秒,如何只取其中的年、月、日,赋值给数据库中的date列呢?

WQ 2002-03-15
  • 打赏
  • 举报
回复
CTime::Format
CString Format( LPCTSTR pFormat ) const;

CString Format( UINT nFormatID ) const;

Return Value

A CString that contains the formatted time.

Parameters

pFormat

A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding CTime component. Other characters in the formatting string are copied unchanged to the returned string. See the run-time functionstrftime for details. The value and meaning of the formatting codes for Format are listed below:

%D Total days in this CTime


%H Hours in the current day


%M Minutes in the current hour


%S Seconds in the current minute


%% Percent sign
nFormatID

The ID of the string that identifies this format.

Remarks

Call this member function to create a formatted representation of the date/time value. If the status of this CTime object is null, the return value is an empty string. If the status of CTime is invalid, the return value is an empty string.

Example

// example for CTime::Format and CTime::FormatGmt
CTime t( 1999, 3, 19, 22, 15, 0 );
// 10:15PM March 19, 1999
CString s = t.Format( "%A, %B %d, %Y" );
ASSERT( s == "Friday, March 19, 1999" );

yheysj 2002-03-15
  • 打赏
  • 举报
回复
CTime Time;
CString m_strFilter=time.Format();
不过呢,你最好看看msdn!!
dou_ya 2002-03-14
  • 打赏
  • 举报
回复
CString strTime = time.Format();
CString str = time.Format("%Y-%M-%D %h:%m:%s");
还可以在Format(str)指定日期地格式。详情参见MSDN。
pudding 2002-03-14
  • 打赏
  • 举报
回复
谢谢了!
还想请教:如何与数据库中的datetime类型的数据(日期一列)进行比较?
pudding 2002-03-14
  • 打赏
  • 举报
回复
先谢谢您,我试试看!
Yvesyu 2002-03-14
  • 打赏
  • 举报
回复
可以用CTime的成员函数Format生成m_strFilter

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧