Solved

How to write current time into SYBASE database?

Posted on 1998-12-13
5
1,032 Views
Last Modified: 2012-08-13
I want to write current time into SYBASE database and SQL ANYWHERE database by using ODBC... , my codes is somewhat like the following:
    time_t now;
    time(&now); // get current time
     ...
    SQLExeDirect(hsmt,"INSERT INTO TABLENAME(CURRENTTIME..) VALUES(now..)",SQL_NTS);
    but It cannot write successfully,so I hope some one could write correct codes for me!
    Thank you very much!
(PS: I'm using VC++5.0(SDK,not MFC) under Windows NT 4.0,and the Database are SYBASE SYSTEM 10 and SQL ANYWHERE provide with PB)
0
Comment
Question by:aiqing
[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
5 Comments
 
LVL 9

Expert Comment

by:david_levine
ID: 1098511
When you say it isn't successfuly, what does that mean? Does it put something into the column, but not what you expected?

The easiest way to insert a time is using a string such as "12/13/98 12:27:30"

Can you try doing a sprintf to create the appropraite looking string?

Also, when specifying a value in a program that isn't a literal, you usually precede it with a :. In your example it would be VALUES(:NOW) though I'm not 100% sure about C and the SQLExeDirect funciton.

Let me know how it works.
David
0
 

Author Comment

by:aiqing
ID: 1098512

I do not want to write time to Database by using string,I want to
use the according Time STRUCTURE such as SYSTEMTIME,TIMESTAMP to
complete this function!
(PS:my method refered last time cannot work)
0
 

Accepted Solution

by:
GeoffS earned 50 total points
ID: 1098513
Why not just default the column to "Predefined Timestamp" in the Advanced Column properties. This way the server will automatically update the column for you when you insert the row.

Regards, Geoff

0
 
LVL 9

Expert Comment

by:david_levine
ID: 1098514
aiqing,

Why don't you get a plain SQL statement to work the way you wantr to via isql or whatever front-end you use. Once you get it where it works, let me know the exact statement you used and I'll help again.

We only use strings to update date/time fields (or allow the database to do it automatically as GeoffS mentions).

David
0
 

Expert Comment

by:shaube
ID: 1098515
Try this:
SQLExeDirect(hsmt,"INSERT INTO  
TABLENAME( your_date_field )
VALUES( getdate() )",SQL_NTS);
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Getting to know the threat landscape in which DDoS has evolved, and making the right choice to get ourselves geared up to defend against  DDoS attacks effectively. Get the necessary preparation works done and focus on Doing the First Things Right.
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

626 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