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
Solved

How to write current time into SYBASE database?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article describes how to reset your Windows 10 password when you've forgotten it.
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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