Solved

How to write current time into SYBASE database?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SyBase SQL Syntax 7 323
Want to replace a WordPerfect code with a equivalent MS Word code to create a document 2 439
SQL Syntax 10 82
sybase output only middle rows 4 46
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
This article discusses how to implement server side field validation and display customized error messages to the client.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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