How do I get the date part from datetime variable ?

How do I get the date part from datetime variable ?

e.g
declare @start_time datetime

select @start_time = "10/31/2003"

This puts date and current System time into the variable.

I use this for some comparison on datetime field on database. But when I do
the comparison, I want to do the comparison without time part on database
field and my variable. How do I do that ?

Thanks


0
phari
12/5/2003 10:51:59 PM
sybase.ase.general 8655 articles. 0 followers. Follow

2 Replies
5602 Views

Similar Articles

[PageSpeed] 8

Check out the datepart function.

In article <3fd10c0f$1@forums-1-dub>, <phari> says...
> How do I get the date part from datetime variable ?
> 
> e.g
> declare @start_time datetime
> 
> select @start_time = "10/31/2003"
> 
> This puts date and current System time into the variable.
> 
> I use this for some comparison on datetime field on database. But when I do
> the comparison, I want to do the comparison without time part on database
> field and my variable. How do I do that ?
> 
> Thanks
> 
> 
> 
0
Mark
12/5/2003 11:00:13 PM
or CONVERT function (pay attention to third parameter)

example:
select convert(varchar(10),getdate(),112)
result:
20031208   -<-- YYYYMMDD

select convert(varchar(10),getdate(),108)
result:
17:40:30   -<--- HH:MM:SS

Regards,
    Andrew

"Mark Maslow" <mark.maslow@sierraclub.org> wrote in message
news:MPG.1a3aab35f3ce419896ef@forums.sybase.com...
> Check out the datepart function.
>
> In article <3fd10c0f$1@forums-1-dub>, <phari> says...
> > How do I get the date part from datetime variable ?
> >
> > e.g
> > declare @start_time datetime
> >
> > select @start_time = "10/31/2003"
> >
> > This puts date and current System time into the variable.
> >
> > I use this for some comparison on datetime field on database. But when I
do
> > the comparison, I want to do the comparison without time part on
database
> > field and my variable. How do I do that ?
> >
> > Thanks
> >
> >
> >


0
Andrew
12/8/2003 2:52:54 PM
Reply:

Similar Artilces:

get only date from a date with a datetime format
i have a problem with dates when it comes to searchingbasically, SQL searches for a date including the seconds,but i only need to date so that in any given time, it will yield a result.here's a part of my code-behind code: reqNo = RequisitionsLogic.GetReqNoByDate(currentDate, requestorCode)and here's the SQL statement created in a TableAdapter:SELECT RequisitionNoFROM RequisitionsWHERE (RequisitionDate = @RequisitionDate) AND (RequestorCode = @RequestorCode) take a look with this, don't just accept influenceshttp://thedailyarr.tkhttp://www.ftpx.com/index...

Get date portion from DateTime (with DateTime property)
    private string _Date;    public string Date    {        get { return _Date; }        set { _Date = value; }    } objDados.Date = Convert.ToDateTime(drResult["APP_DATE"]).Date.ToString("dd/MM/yyyy"); If I replace _Date from string to DateTime, how can I get only date portion from DateTime? ThanksBest regards,Ivan Andrade Hi  you could always copy it. But I'd put the Date property to be of DateTime type. Something like:  &...

Parse DateTime into Date or select DateTime as Date from Access
I am getting DateTime values out of an Access Database and I want to only use the Date part of this field. I have tried to cast the returned value to a DateTime value and then format the DateTime to only show the Date part in the toString() fcn. <asp:Label runat="server" Text='<%# getDate(DataBinder.Eval(Container, "DataItem.ACTIVE_FROM"))%>'> But I can't cast the object to a DateTime object. I have also tried using DateTime.Parse() but this gives an error saying that the format is not correct.         {       ...

Get Date Only from DateTime in GridView
Howdy Folks,I'm loading a GridView from an Access DataBase. I've been trying every thing I can come up with trying to figure out how to get the Date only from a GridView Field. I've used a TableAdapter/DataTable, AccessDataSource, and Custom SQL Statements to load the GridView. No matter what I do, the field always has "12:00:00 AM" attached to the Date.The Date is set to Short Date in the Access DataBase I used the following code which takes the field item and formats it to ShortDate, IF I put the result in a TextBox. But when I put it in the GridView the time is always attached.D...

Getting parts of DateTime field
Hi everyone, I want to get year, month, day and time parts of a DateTime field in sql, Can help me? There are many datetime functions you can use. For example: You can use Year(dtColumn), Month(dtColumn) to get year and month returned in integer format. You can also  use DATEPART function to get the part you want, for example: Datepart(yyyy,dtColumn) to get year. Here is the full list from MSDN library: http://msdn.microsoft.com/en-us/library/ms174420.aspx    Limno...

Get Date portion from Datetime
Hi all How to get just the date portion from a datetime field from sql server? thanks a lotBest regards,Ivan Andrade CONVERT(varchar,yourDateColumn,101)   Check out CONVERT function in BOL for more options.***********************Dinakar NethiLife is short. Enjoy it.*********************** Hi I'm getting a System.IndexOutOfRangeException error in resultset while(result.Read())    {    this.escritorios.codEscritorio = (int) result["Cod_escritorio"];    this.filiais.codFilial = (int) result["Cod_filial"];   &nb...

getting just the date or from DateTime field
Hi, I have used smalldatetime datatype to store my date and time values. i want to store just the date or time but the problem is it stores both the date and time. For eg, if i add the the date 03/11/2004, it also the stores the current time automatically. so the new value will be something like 03/11/2004 10:00:00 AM where i want just 03/11/2004. further problem is even though i managed to store just the date like 03/11/2004 in the database, whole date and time shows up when i display it in my pages. any help will be appreciated. thanx,-keeara g------------------ If i want to dis...

Getting week of the month from a DateTime variable?
Hello,How do I get the week number of the month a DateTime value falls under? For example, March 3, 2007 would be in week 1 and March 4, 2007 would be in week 2 thx  theres no native week of month function. The closest you can get is GetWeekInYear , which you can pass the 1st day of the month, along with the day of week that the week starts on. You can then loop, adding 7 days to the date to calculate the other weeks in the month. Cathal http://groups.google.com/group/microsoft.public.access/msg/996e69eb76a63f76  Wayne Morgan wrote: > This one is a little si...

Getting date and datetime system formats
Hi, How can I get the default date and datetime formats PowerBuilder uses for string conversion? Thanks in advance, Yves. I believe that PB checks the Windows regional settings and uses the values there. On Wed, 28 Feb 2001 11:18:16 +0100, in powersoft.public.powerbuilder.powerscript Yves Joosen <yves.joosen@be.xrtcerg.com> wrote: >Hi, > >How can I get the default date and datetime formats PowerBuilder uses for >string conversion? > >Thanks in advance, >Yves. > > Bruce Armstrong [TeamSybase] http://www.needhim.org ---== Po...

How to get Date and Time value in a variable
--Boundary_(ID_AnjDfkCotgyVS+Abi1/c+A) Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Hi all, I thought getting the date would be like how it's in a shell script `date` but it does not seem to be working. Could someone please advise me on this I tried searching archives on "date" but didn't get anything useful. It's possible I'm looking in the wrong place. Thanks in advance --Boundary_(ID_AnjDfkCotgyVS+Abi1/c+A)-- On Jun 12, Leila Lappin said: >I thought getting the date would be like how it's in a shell script...

Accessing various parts of the Date or DateTime
How do I access the parts of the Date or DateTime object. I like to get 1. the day of the month formatted in two digits (01, or 12) 2. month of the year formatted in two digits (01, or 12) 3. and year (01 or 05) Hi jty202, Try out the following. Let us know if this is not what you had in mind. [VB.NET] Response.Write(DateTime.Today.ToString("dd")) Response.Write(DateTime.Today.ToString("MM")) Response.Write(DateTime.Today.ToString("yy")) [C#] Response.Write(DateTime.Today.ToString("dd")); Response.Write(Da...

get DateTime.Now.Date in sql
 Hi, Im making an c# asp.net website. I use an dataset and an gridview.  I will fill an gridview with users with the follow sql query:SELECT     UserIdFROM         StatsWHERE     LunchDate =  DateTime.Now.Date()How can I get all the users with the date of today?I have try the follow solution but it doesnt work:SELECT     UserId FROM         Stats WHERE     LunchDate =  @LunchDateIn the objectDataSource I hav...

getting date in between 2 date
how do i get the date in if it is within the 2 date? er... don't know how to phrase i think my sql is something like this: SELECT * From Transaction WHERE Date BETWEEN 01/08/1900 AND 31/08/2000 BTW i declare my Date as date/time(short date) is it possible with the sql? it display Syntax error in FROM clause. SELECT * From [Transaction] WHERE [Date] BETWEEN #01/08/1900# AND #31/08/2000# Now, this presumes that the machine in question is expecting dates in dd/mm/yyyy format. Note that Transaction and Date are likely reserved words, and so I have enclosed them in [ and ...

Get the dates between two dates
Hi all, I want to get all the date between two dates. For example I have a StartDate="12/5/2003" and a EndDate="12/7/2003" the result should be 12/5/2003 12/6/2003 12/7/2003 Ant help is appreciated Thanks for ( DateTime theDate=StartDate ; theDate<=EndDate ; theDate.AddDays(1) ) { // Do something...theDate.ToShortDate() would give the string... } Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog I get a syntax error as :"For loop variable cannot be of type Date" Hmm. The below work...