Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 7th, 2004, 03:45 AM
Authorized User
 
Join Date: Dec 2003
Location: sg petani, kedah, Malaysia.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to suzila
Default sql - comparing current time

Hi,

I have 1 table with 3 column(session(eg:1),start(eg: 8:00:00 AM),end (eg:10:00:00 AM)
I want to determine which session I'm in now by using sql statement,
just like this :

time = date.now

"select session from table1 where time > start and time < end"

Is it works ? or there is another way to make it?..thanks
__________________
Suzila
Reply With Quote
  #2 (permalink)  
Old May 7th, 2004, 10:32 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You could also use BETWEEN .. but yes- that pseudo code looks about right.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #3 (permalink)  
Old May 11th, 2004, 02:01 AM
Authorized User
 
Join Date: Dec 2003
Location: sg petani, kedah, Malaysia.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to suzila
Default

yes, the logic is seem like to correct but the main problem are, the sql statement cannot compare the 'time' with 'start'

time = '8:00:00 AM'(current time) so do start = 8:00:00 AM( database)
('ive try use convert and cast)

anyone knows? i'm using sql server..thanks a lot
Reply With Quote
  #4 (permalink)  
Old May 11th, 2004, 08:36 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

what do you mean it can't compare it.. what kind of error are you getting?


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #5 (permalink)  
Old May 11th, 2004, 07:54 PM
Authorized User
 
Join Date: Dec 2003
Location: sg petani, kedah, Malaysia.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to suzila
Default

yes, it can't compare it.
I didn't get any error but it didn't produce any output..
I'm using convert.. like this : convert(datetime,time,9)
9 - because i'm using AM and PM






Reply With Quote
  #6 (permalink)  
Old May 12th, 2004, 08:38 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Please paste your sql statement here for review.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #7 (permalink)  
Old May 13th, 2004, 03:59 AM
Authorized User
 
Join Date: Dec 2003
Location: sg petani, kedah, Malaysia.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to suzila
Default



column 1 : session (eg: 1),
column 2 :start (eg: 8:00:00 AM),
column 3: end (eg:10:00:00 AM)

t= date.now

SELECT session, CONVERT(datetime, start, 9) AS start, CONVERT(datetime, end, 9) AS end
FROM dbo.sessi
WHERE (end > (CONVERT(datetime, t, 9))) AND (start < =(CONVERT(datetime, t, 9)))





Reply With Quote
  #8 (permalink)  
Old May 14th, 2004, 12:05 AM
Authorized User
 
Join Date: Dec 2003
Location: sg petani, kedah, Malaysia.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to suzila
Default

i just solve my problem,
my solution like this

SELECT session
FROM dbo.sessi
WHERE
(start < CONVERT(varchar(30), GETDATE(), 114)) AND (end > CONVERT(varchar(30), GETDATE(), 114))

thank you for help me..:D

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Current Date and Time in XSLT devMc XSLT 6 October 21st, 2007 04:49 AM
getting current date and time in xslt 1.0 ashyabhi_hp XSLT 1 September 24th, 2007 03:17 AM
Gridview, Eval and Current Time timeware ASP.NET 2.0 Professional 3 September 20th, 2006 06:06 AM
comparing date/time fields on form validation Lucy Javascript How-To 1 June 20th, 2006 09:22 AM
Check to See if Current Time is between hours mvollmer Classic ASP Professional 5 July 28th, 2004 07:49 PM



All times are GMT -4. The time now is 12:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.