473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MsSQL - Not storing and returning milliseconds

113 100+
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:
Expand|Select|Wrap|Line Numbers
  1. sqlStatement = "INSERT INTO scores (name,email,usertime,milliseconds) VALUES('" & fName & "','" & fEmail & "',convert(datetime, '" & fTime & "', 21),'" & fMilliseconds & "')"    
  2.  
and my display query is:
Expand|Select|Wrap|Line Numbers
  1. 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"
  2.  
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.
Aug 22 '08 #1
4 3123
ck9663
2,878 Expert 2GB
Try using 109 as type parameter.

Read more here

-- CK
Aug 22 '08 #2
Delerna
1,134 Expert 1GB
and what is the ,9 in the convert function for?

Shouldn't it be just

convert(varchar(30),min(usertime)) AS mintime
Aug 23 '08 #3
chromis
113 100+
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.
Aug 26 '08 #4
chromis
113 100+
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
Aug 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
2
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...
0
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...
4
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...
2
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...
3
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...
9
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...
1
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? ...
0
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...
1
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...
0
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...
0
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.