Get Date portion from Datetime

Hi all

How to get just the date portion from a datetime field from sql server?

thanks a lot


Best regards,

Ivan Andrade
0
Roberot
6/15/2006 9:58:39 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

5 Replies
200 Views

Similar Articles

[PageSpeed] 11

CONVERT(varchar,yourDateColumn,101)
 
Check out CONVERT function in BOL for more options.

***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
6/16/2006 4:27:38 AM

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"];
    this.escritorios.nomeEscritorio = (string) result["Nome_escritorio"];
    this.escritorios.periodoInicioEscritorio = result["Periodo_inicio_escritorio"].ToString();
    this.escritorios.periodoFimEscritorio = result["Periodo_fim_escritorio"].ToString();
   }

when using convert function, how to solve that? thanks a lot

CREATE PROCEDURE ng_RetornaEscritorio
(
    @Cod_escritorio  int,
    @Cod_filial   int OUTPUT,
    @Nome_escritorio  nvarchar (50)  OUTPUT,
    @Periodo_inicio_escritorio datetime OUTPUT,
    @Periodo_fim_escritorio datetime OUTPUT
)
 AS
SELECT Cod_escritorio, Cod_filial, Nome_escritorio, convert(varchar,Periodo_inicio_escritorio,103),
convert(varchar,Periodo_fim_escritorio,103) FROM Negocios_escritorios
WHERE
Cod_escritorio = @Cod_escritorio


GO


Best regards,

Ivan Andrade
0
Roberot
6/16/2006 1:57:38 PM

I don't understand Portuguese but try the link below for all the SQL Server DateTime convert codes.  Hope this helps.

http://www.sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk


Kind regards,
Gift Peddie
0
Caddre
6/16/2006 2:14:05 PM

I'm getting that range exception error when requesting this parameter:

SqlParameter paramPeriodo_inicio_escritorio =

new SqlParameter("@Periodo_inicio_escritorio", SqlDbType.DateTime, 8);

paramPeriodo_inicio_escritorio.Direction = ParameterDirection.Output;

objCommand.Parameters.Add(paramPeriodo_inicio_escritorio);

 

Maybe it occurs because the convertion from datetime to varchar? i've change it but it is not working yet


Best regards,

Ivan Andrade
0
Roberot
6/16/2006 2:18:38 PM

I solved that, doing the following

 convert(varchar,Periodo_inicio_escritorio,103) as dataInic, ...

 

while

(result.Read())

{

this.escritorios.codEscritorio = (int) result["Cod_escritorio"];

this.filiais.codFilial = (int) result["Cod_filial"];

this.escritorios.nomeEscritorio = (string) result["Nome_escritorio"];

this.escritorios.periodoInicioEscritorio = result["dataInic"].ToString();

this.escritorios.periodoFimEscritorio = result["dataFim"].ToString();

}

 

Thank you all


Best regards,

Ivan Andrade
0
Roberot
6/16/2006 2:43:28 PM
Reply:

Similar Artilces:

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:  &...

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...

SQL DateTime and Searching for just the date portion
I have a SQL DB with a column called time_occurred that is formatted like ( 7/28/2004 7:10:30 AM ). What I need to do is run a report based on just the month day and year portion. I am using the calendar control so mins, sec and milliseconds are not available nor do I really need them. I am running the Query with this Stored Procedure ALTER PROCEDURE dbo.Prodecure1 ( @WhereClause varchar(8000) ) AS -- Create a variable @SQLStatement DECLARE @SQLStatement varchar(8000) -- Enter the dynamic SQL statement into the variable @SQLStatemen...

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...

.NET DateTime and SQL Server DateTime problem
.NET DateTime and SQL Server DateTime problem  I have the following if statement in an SQL stored procedure: IF (@Image = 1 AND @DateTimeUploaded = (SELECT ImageMainDateTime FROM Images WHERE UserID = @UserID))   The value of the @DateTimeUpdated variable was taken from the ImageMainDateTime field when the data was requested by a ASP.NET webpage and is passed back here when that page is submitted so I can compare what the DateTime was when the data was requested with what it is now, in other words I’m doing a concurrency check (I can’t use TimeStamp for many reasons, ...

Getting just the date from a "datetime" sql column along with other data of different formats
Hi. I have a web page that gets the current user, then goes into a database and gets a list of invoices, this includes: invoice numbers, the date of the invoice, the date the invoice was paid, and the amount of the invoice. The data is then bound to a repeater control and displayed. i need a way to get just the date and not the date and time from the datetime columns. Here is my code that i have now: This next part gets the current user, then creates the selection string and binds the repeater to the data.Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ...

Get Date and compare with Date.Now in T-SQL
I am trying to set an alert to user for a project which will due on the particular date. How to compare the DateTime due date  which I get from the database with the Date.Now in stored procedure? Thanks in advance.Best regards,Ron. Make sure they are both in the same format. Many different ways to accomplish. The example below would convert both to a date: select * from table where convert(nvarchar(15),DueDate,101) = convert(nvarchar(15),Date.Now(),101) Thanks samsta, but I got an error when I am using Date.Now(). Then, I change with GetDate() function and works just ...

Convert .NET DateTime format to SQL DateTime format
Hi!!I'd like to know if there is a function to convert the DateTime format used in C# (VS2005) : dd/mm/yyyy HH:mm:ss to the format used in SQL Databases: yyyymmdd HH:mm:ssThanks folks!...

Extract date,month, year from the date getting from sql table
Hello All, i have three textboxes in a page and i want fill those textboxes  with the date, month,year respectively..... i have a datecreated column in discount table in a mm/dd/yy format ...how to extract the date, month, year from this format and put the value in textboxes..? Any help.. Thanks.. AnneAnne You could do it from SQL - using DATEPART and/or DATENAME function. My example casts all values to varchar, and makes sure day and month are given with two digits: SELECT DATENAME(Year, dateCreated) AS yr, RIGHT('0' + CAST(DATEPART(Month, dateCreated) AS varchar...

How to get the current date in C# and how do I pass this date to SQL Server
I am writing a ASP.NET C# web application. I will need to store the date in one field in one of my tables. It appears that I need to use the datetime data type for the date in SQL Server 2005. So I have a question 1.) How do I get today's date in C# and how should this be passed to SQL server? you can get the current date directly in SQL using getdate()KH Doing it in C# will return you the client system date. Getting the current date in SQL will ensure all datetime recorded in your application are in sync. If you are using the date for some sort of comparison determine the sequence of ...

convert an sql datetime column to .net datetime data type in front end...?
I have a field (ldate) in a table that typically displays data in the following format:2007-11-12 20:30:47.000In the front end I want the time and the date separately. But as I try to cast it to a datetime object it is giving me a System.NullReferenceException. What I tried to do was just this: Protected Sub gvTopics_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTopics.RowDataBound Dim img As Image = gvTopics.FindControl("imgIcon") Dim lbDate, lbTime As Label lbDate = gvTopics.FindControl(...

Get last modified date for sql objects in SQL server 2005 to track database changes.
For frequent migration to different environment we have to provide scripts for any database changes, most of the time developer forget to send few of the scripts which causes error in the other environments. I am using SQL server 2005.I was looking for any sql query which can list the create date and modify date of table, stored procedure, views etc in a database.I google and found the below query but I get the below error message:" Invalid object name 'sys.objects'."SELECT nameFROM sys.objectsWHERE type = 'P'AND DATEDIFF(D,modify_date, GETDATE()) < 7Note: I do ...

How to get todays date in format YY/MM/DD and to compare it to another date passed into the sql
I need to do the following and am hoping someone can help me out. I have C#(asp.net app) that will call a stored procedure. The C# will pass in a date to thestored procedure. The date is in the format YY/MM/DD. Once inside of the stored procedure, the datepassed into the stored proc needs to be compared to todays date. Todays date must be determined inthe SQL. So basically here is my pseudo code for what I am trying to accomplish. Basically I just am afterthe comparison of the two values: If @BeginDate < TodaysDate The difficult part is how to obtain the value for "TodaysDate&qu...

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.         {       ...

Web resources about - Get Date portion from Datetime - asp.net.sql-datasource

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: &lt;span class="utctime"&gt;2010-01-01 11:30 PM&lt;/span&gt; I would like a jquery script or plug in to convert every utctime ...


Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ...

Limburg.be - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: limburg.be Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows http://simplesideias.com.br/usando ...

Resources last updated: 12/6/2015 8:45:52 PM