Jump to content

Help using SQL and datetime

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Orush7

Orush7

    Newbie

  • Members
  • Pip
  • 2 posts
Hi there,
I'm new here and I'm pretty much a newbie so I hope you could help me...

I need to compare a datetime from a datebase to a date from DateTimePicker in order to get a datatable only with dates after the specific DateTimePicker date. (Ugh I really dont know how to explain it, I hope you got me. If you didnt just say and I'll try to give a wider explanation)

How can I write it correctly in SQL?
WHERE Date>'???'


Thanks in advance!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
It depends a little on the database type. Oracle handles dates differently from SQL Server, which is different from MySQL...
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Orush7

Orush7

    Newbie

  • Members
  • Pip
  • 2 posts
I have SQL Server


Thanks

#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
in ADO.NET
in your query instead of trying to concat in a date value, you use
@datefieldname

Then in your code, you want to add
command.Parameteres.AddWithValue("@datefieldname", datetimepicker.Value);

i might be wrong on the .Value, I havent used one (Date Time Picker) in recent memory

but this way, in your code, you dont need to worry about qualifiers, you can just treat the parameter as a SQL declare

Edited by sam_coder, 15 January 2011 - 08:02 AM.
clarifying





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users