MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 16th, 2004, 11:30 PM
trentmurray trentmurray is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Australia
Posts: 96 trentmurray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Inserting time and comparing times

hey all,

I have a datetime field in a table, now whats the command to insert the current date and time down to milliseconds into a row of that field? (seconds would be fine, but the smaller the better)

eg:

id -> 1
logtime -> 12/10/2004 16:00:23:55

For this one i've tried:
Code:
INSERT INTO tblSession ( logtime ) VALUES ( now() )


But this doesnt work, and that's what i do for mySQL databases, so i'm confused.

My next question is, how do i compare to records in the database? What's the SQL Query?

And i guess i'll throw in another question for good luck. In mysql there is an option to make an int field auto_increment, how do i do this in MS SQL?

Thanks for your help in advance.

Reply With Quote
  #2  
Old November 17th, 2004, 03:42 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Code:
INSERT INTO tblSession ( logtime ) VALUES ( getdate() )


datetime columns are compared as any other columns.

The equivivalent of auto_increment is the identity property.

Reply With Quote
  #3  
Old November 17th, 2004, 07:03 PM
trentmurray trentmurray is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Australia
Posts: 96 trentmurray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
thanks for that, but i have one more question.

Say i don't want to compare times as so much as see if a logtime is more than 15mins old?

How would i do that?

Thanks for your help

Reply With Quote
  #4  
Old November 18th, 2004, 06:02 AM
sstoyan sstoyan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 7 sstoyan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 4 sec
Reputation Power: 0
try with DATEDIFF, like

select case when datediff(mi, time1, time2) > 15 then 'on time'
else 'out of time' end




---------------------------
dev @
viewmoresoft.com
tools for your database

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Inserting time and comparing times


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT