|
-
May 17th, 2006, 03:50 AM
#1
Another Date and Time question . But it's more difficulty!!!
How can I insert the System time(current time) into access like the former
in C++ (eg. 2006-04-19 16:41) ???
The time in access is datetime type!!!
Jeff Fan
No change is the worst!!!
The principal of mine
msn: [email protected]
If you like coding , add me.
-
May 17th, 2006, 03:53 AM
#2
Re: Another Date and Time question . But it's more difficulty!!!
I know in Java , it can use the method getdate().
But I have scanned many meterials , that I can't find in C++
Jeff Fan
No change is the worst!!!
The principal of mine
msn: [email protected]
If you like coding , add me.
-
May 17th, 2006, 04:15 AM
#3
Re: Another Date and Time question . But it's more difficulty!!!
retcode=SQLExecDirect(hstmt,(UCHAR*)"insert into package(Protocol,SrcAddr,DstAddr,SrcPort,DstPort,TotalLen,GetTime)values('a','b','c','d','e',2000000,'3-2-2006')",SQL_NTS);//SQL语句执行出错
the quote '3-2-2006' of the sentence , can i substitue with the system
time???Like the first thread.
Jeff Fan
No change is the worst!!!
The principal of mine
msn: [email protected]
If you like coding , add me.
-
May 17th, 2006, 07:04 AM
#4
Re: Another Date and Time question . But it's more difficulty!!!
you can try COLEDateTime.
<pre>
COleDateTime curTime= COleDateTime::GetCurrentTime( );
CString str = curTime.Format(_T(" %Y-%m-%d %I:%M"));
</pre>
-
May 17th, 2006, 07:45 AM
#5
Re: Another Date and Time question . But it's more difficulty!!!
- Using C standard library functions:
Code:
time_t timer = time(NULL);
tm *loctime = localtime(&timer);
char* pszDateTime = (char*)malloc(17);
sprintf(pszDateTime,
"%d-%02d-%02d %02d:%02d\0",
loctime->tm_year + 1900,
loctime->tm_mon,
loctime->tm_mday,
loctime->tm_hour,
loctime->tm_min);
// ... you have now formatted datetime string
free(pszDateTime);
- Using MFC:
Code:
CTime locTime = CTime::GetCurrentTime();
CString strTime = locTime.Format(_T("%Y-%m=%d %H:%M"));
// also can use COleDateTime instead of CTime
- Using Windows API
Code:
SYSTEMTIME st;
::GetLocalTime(&st);
char* pszDateTime = (char*)malloc(17);
sprintf(pszDateTime,
"%d-%02d-%02d %02d:%02d\0",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute);
// ... you have now formatted date string
free(pszDateTime);
NOTES:
- You can further substitute datetime string in the SQL statement also by using sprintf or in case of using MFC by CString::Format.
Example:
Code:
CString strSQL;
strSQL.Format(_T("INSERT INTO Cats(Name, Owner, Birthdate)")
_T("VALUES('Kitty','John Smith','%s')"),
strDateTime);
- The above are just examples. You can also use sprintf/CTime::Format/CString::Format to direct format the SQL statement at once (without an intermediary datetime string).
Example:
Code:
CTime locTime = CTime::GetCurrentTime();
CString strSQL;
strSQL.Format(_T("INSERT INTO Cats(Name, Owner, Birthdate)")
_T("VALUES('Kitty','John Smith','%04d-%02d-%02d')"),
locTime.GetYear(),
locTime.GetMonth(),
locTime.GetDay());
- The examples above give the local time and not the system time (UTC).
- Please do not create other threads with links to this one, simply to show that you have a problem here.
Last edited by ovidiucucu; May 17th, 2006 at 08:06 AM.
Reason: example added
-
May 17th, 2006, 07:17 PM
#6
Re: Another Date and Time question . But it's more difficulty!!!
I'm sorry that I said by mistake , the former should be 2006-04-19 16:41:56
, it should append the secend.
By the way , what's the head file in different enviroment? (eg. API and MFC)
Jeff Fan
No change is the worst!!!
The principal of mine
msn: [email protected]
If you like coding , add me.
-
May 18th, 2006, 01:24 AM
#7
Re: Another Date and Time question . But it's more difficulty!!!
 Originally Posted by [email protected]
I'm sorry that I said by mistake , the former should be 2006-04-19 16:41:56
, it should append the secend.
So, what's the problem? Given examples above, choose one of methods, read documentation for sprintf, and/or CString, and/or CTime, and format the string as you wish.
 Originally Posted by [email protected]
By the way , what's the head file in different enviroment? (eg. API and MFC)
If you have installed MS Visual C++, you can use AppWizard to create an MFC or Win32 Application. The wizard will automatically include the required headers (for example <afxwin.h> or <windows.h>).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|