Solved

How to write current time into SYBASE database?

Posted on 1998-12-13
5
1,004 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Agreggate sums in sql 1 518
SyBase SQL DataTime Format 6 287
Alternative to ALTER in Sybase 1 389
surrogate key in database world 6 73
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now