Hi,
I know this question has been asked before, but I seem to be getting different results from everyone else.
I want to return times from my db table in this format: hh:mm:ss.mmm using mssql.
I'm using a datetime column to store the information and I am entering the data in this manner: yyyy-mm-dd hh:mm:ss.mmm which is I think the way that mssql stores datetime's in the database. The trouble is when I go to retrieve this data it returns it like this:
01/01/1900 00:00:00
09/09/2008 01:01:02
With no milliseconds.
My insert query is: -
sqlStatement = "INSERT INTO scores (name,email,usertime,milliseconds) VALUES('" & fName & "','" & fEmail & "',convert(datetime, '" & fTime & "', 21),'" & fMilliseconds & "')"
-
and my display query is: -
sqlStatement = "SELECT scores.id, scores.name, scores.email, scores.usertime FROM scores INNER JOIN ( SELECT T2.name, T2.email, convert(varchar(30),min(usertime),9) AS mintime FROM scores T2 GROUP BY T2.name, T2.email ) T3 ON scores.name = T3.name AND scores.email = T3.email AND scores.usertime = T3.mintime ORDER BY T3.mintime"
-
Can anyone point out where I'm going wrong? I'm guessing it's to do with the convert() function. I've trawled the internet but not found the info i need.
Thanks.
4 3123
Try using 109 as type parameter.
Read more here
-- CK
and what is the ,9 in the convert function for?
Shouldn't it be just
convert(varchar(30),min(usertime)) AS mintime
thanks ck. Does the style number effect the way in which the timestamp is entered into the database, so you can enter 12/12/2003 12:10:09AM instead of 12 12 2003 12:10:09AM and with the style number 109 it will enter it in the db as
12 12 2003 12:10:09AM?
I'm struggling because I've tryed a few of the styles and none of them seem to allow me to enter milliseconds...or at least the milliseconds are not being returned when i query the database.
and what is the ,9 in the convert function for?
Shouldn't it be just
convert(varchar(30),min(usertime)) AS mintime
The 9 is for the style of the conversion. Ref Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kieran Benton |
last post by:
Hi,
I have quite a lot of metadata in a WinForms app that I'm currently storing
within a hashtable, which is fine as long as I know the unique ID of the
track (Im storing info on media files). Up...
|
by: jblankenburg |
last post by:
Please help!
I am hunting high and low for an equivalent function for MSSQL's
DATENAME function. Here's the spec on the function from MSSQL's Books
Online:
DATENAME
Returns a character...
|
by: LizRickaby |
last post by:
My client has several Access databased that they wanted converted into MSSQL to be able to access them online (excuse the pun). I added the first Access database, LenderPrograms, as a table in the...
|
by: pks83 |
last post by:
In MSSQL I am using datetime as the column type and trying to execute the below mentioned query
select time from tickets where ticket_id = '1';
when i execute the query on sql manager window it...
|
by: pks83 |
last post by:
In MSSQL I am using datetime as the column type and trying to execute the below mentioned query
select time from tickets where ticket_id = '1';
when i execute the query on sql manager window it...
|
by: Shawn Beasley |
last post by:
Hi List,
I am searching franticly for a solution (or the procedure) to setting
the coding of a new DB to UTF-8. I can find no setting in the Server
Manager, during creation of the DB, to...
|
by: chromis |
last post by:
Hi,
I've never coded in ASP before and I'm trying to port a couple of simple PHP files to ASP.NET. The first file addScores.php takes form data and a hash and inserts the data into the db, it...
|
by: chromis |
last post by:
Hi,
I wouldn't post such a lazy question usually but I've got to have this sorted for the end of the day, sorry! Could someone tell me how to write this statement in MSSQL please?
...
|
by: chromis |
last post by:
Hi,
I've recently been porting a little php / mysql script over to asp / mssql and I've got issues with the timestamp data type. With mysql i could easily insert 01:01:01 into the timestamp...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |