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



4/15/2008 2:48:16 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 53

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(2)),2) AS mth, RIGHT('0' + CAST(DATEPART(Day, dateCreated) AS varchar(2)),2) AS day FROM myTable

Datepart function is also available in .NET if you want to retrieve the date as it is and extract dateparts in the application rather than the database. Look at datepart method in the .NET documentation.

If this answered your question, be sure to mark it as the answer. Then you give credit to people who help you, and others will know that the question is already answered.
My SQL Server blog (swedish): http://www.underlandet.com/SqlServer
4/15/2008 4:50:00 AM






May the Force be with you
4/15/2008 4:54:24 AM



Do like this ,


if it is you get sql datarows in datatable then,

 dt is datatable and fill it with discount table...

TextBox1.Text = Convert.ToDateTime(dt.Rows[0]["Date"].ToString()).Date.Day.ToString();  <-- For Day like 15

TextBox2.Text = Convert.ToDateTime(dt.Rows[0]["Date"].ToString()).Date.Month.ToString();  <-- For Month like 04


TextBox3.Text = Convert.ToDateTime(dt.Rows[0]["Date"].ToString()).Date.Year.ToString();  <-- For Year like 2008



if you do locally i mean with out database table than do like this


DataTable dt = new DataTable();


        TextBox1.Text = dt.Day.ToString();
        TextBox2.Text = dt.Month.ToString();
        TextBox3.Text = dt.Year.ToString();

 Hope this helps you..


If you get answer than "Mark as Read" ...



Jigar Patel
Web Developer
4/15/2008 11:15:46 AM

Similar Artilces:

sql query to display all dates of month when month and year is supplied
hi all,             can anyone tell  how to display the days or dates of a month when month is supplied ?  this is for an timesheet application report which wil show each date of month and respective duration(no. of working hours) of that day for particular user.             expected output will be like this in sql server 2005...                     01/01/2007  &...

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

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

getting date in day/month/year instead of month/day/year
I am trying to get my db to return a date in the format day/month/year but its returning the american version month/day/year. I'm using a DatePart function that converts my date: CREATE FUNCTION dbo.DatePart ( @fDate datetime ) RETURNS varchar(10) AS BEGIN RETURN ( CONVERT(varchar(10),@fDate,101) ) END This returns te american version, can anyone help me to get this to convert the UK way. Thanks have you tried Convert(varchar(10), @fDate, 103) ? check out complete list of style codes in sql server books online. your a star!! Thanks so m...

Dates, Dates, Dates!
Hello all... I am in the process of building an appointment system, and I am trying to see if I can get some pointers on which way to go on this. The first version of this appointment system was very lo-tech, and it stored all of the possible dates/times in the database. Once a user booked an appointment, their information was logged to that date/time, and then that date/time would no longer show in the list of possible openings. This was great for a temporary fix, but with having to pre-populate all of the dates/times, the system would eventually have to be updated to continue on pa...

Sql statement for getting the latest date record from a table
Hey Guys, Can anyone tell me what is the sql statement for getting the latest date set of record from a table.It's urgent and help will be appreciated.   Thanks  select * from tablename where datecolumn = (select max(datecolumn) from tablename)Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever. Same thing can be done with derived tables, especially if you need to get latest date for each group:select myTable.* from myTable inner join (select max(date) as MaxDate from myTable) Max_Date on myTable.Date = Max_Date.MaxDate There ...

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

SQL Stored Procedure
Hi hopefully someone can help. I created the following function to return all dates between a start date and end date:  ALTER FUNCTION fnGetDatesInRange ( @FromDate datetime, @ToDate datetime ) RETURNS @DateList TABLE (Dt datetime) AS BEGIN DECLARE @TotalDays int DECLARE @DaysCount int SET @TotalDays = DATEDIFF(dd,@FromDate,@ToDate) SET @DaysCount = 0 WHILE @TotalDays >= @DaysCount BEGIN INSERT INTO @DateList SELECT (@ToDate - @DaysCount) AS DAT SET @DaysCount = @DaysCount + 1 ...

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

how to get date range from week & year entered in C# or in sql server 2005 query
I want to get date range for eneterd week number & year. Give me example .  C# code or through sql query .Regards,Mahesh--------------------click "Mark as Answer" on the post that helps you.  this Should Help though the code is in vb.net http://social.msdn.microsoft.com/forums/en-US/vbide/thread/43ee5e01-b436-4d5c-a9ca-2070b4fefa75ENJOY .. programming is good for my soul. Can you provide some more detail, what you mean by "date range"?  Also This One If u think Java scrip would be useful 1. function getDateRangeOfWeek(weekNo){ 2...

Error while inserting date in to Sql server database (Year, Month, and Day parameters describe an un-representable DateTime )
Error while inserting date in to Sql server database I am getting error Year, Month, and Day parameters describe an un-representable DateTime. While inserting date to sql server. 1) First time I was using the DateTime.Now function to insert the date to Database but after getting the error(Error - The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value “) Date format is in the form “18/12/2008 12:00:00 AM” 2) I have changed the date format to MM/DD/YY string[] Date = new string[2]; Int32 date, month, year = 0; DateTime InterDate; Date =...

Add date,month,year to date datatype
I am assign date1 as date data typehow to add date or month or year in date1 variable. For ex:date1=12/31/2008add 1 month, the result will be come 1/31/2009add 1 year, the result will be come 12/31/2009add 1 day, the result will be come 1/01/2009Please Help me, Thanks Advance,PentaHari   Try this: DateTime date1 = new DateTime(2008, 12, 31); DateTime date2 = date1.AddMonths(1); DateTime date3 = date1.AddYears(1); DateTime date4 = date1.AddDays(1);Thanks, EdMicrosoft MVP - ASP/ASP.NET...

How to show the date in format date month year ?
Hi, which parameters I need to change in DNN 3.0.12 in order to show the data at the left top not in English but in Italian ? I try to change the file in the web.congif but I dont't solve the problem. <globalization culture="it-IT" uiCulture="it" requestEncoding="UTF-8" responseEncoding="UTF-8"             fileEncoding="UTF-8" /> Thanks. I asume you meen the day and date the [CURRENTDATE] token. There are two ways to get it happen. The first is to asigne your culture to the portal I asume it will bee it-IT as culture. Firs...

Formatting date SQL date to remove time
Hi,I need a way of changing the following SQL statement so that the dates are without the hh:mm:ss tt:"Select DISTINCT([StartDate]) From [Events]"How can this be done?Thanks,Curt. Regards, Curt SELECT CONVERT (VARCHAR, [StartDate], 101) FROM ... For other date formatting types, see http://msdn2.microsoft.com/en-us/library/ms187928.aspxMark replies as answers if they helped you solve the problem. use the following Conversions Convert("urdatecolumn",Varchar,101); and there are more codes for the dateconversions.Its general Syntax is Convert("urdatecolumn",...

Web resources about - Extract date,month, year from the date getting from sql table - asp.net.sql-datasource

Extracts from the Film A Hard Day's Night - Wikipedia, the free encyclopedia
Extracts from the Film A Hard Day's Night is an EP by The Beatles released on 4 November 1964 by Parlophone (catalogue number GEP 8920.) It was ...

Video 2 Photo - extract still pictures from movies on the App Store on iTunes
Get Video 2 Photo - extract still pictures from movies on the App Store. See screenshots and ratings, and read customer reviews.

Vanilla extract ready to sit - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Garcinia Cambogia Extract Exposed: Side Effects and Warnings - YouTube
3 tips to follow before purchasing garcinia cambogia for smart buyers: 1. Make sure the brand has Hydroxycitric acid in it's formula (at least ...

Gideon Haigh book extract: Certain admissions
Speak of meeting &quot;under the clocks&quot; and no Melburnian mistakes your meaning. The indicator clocks over the archway entrance to Flinders ...

Time to extract ourselves from that futile war on IS
The idea that Australia should decide to participate in dropping bombs on Syria is truly appalling.

Read an extract of Derek Pedley's book of suburban lust, greed and murder in Dead By Friday
BOOK EXTRACT: DEAD By Friday, tells the shocking true story of a father's role in a murder plot. Contains graphic content

Thai police extract $400,000 diamond from jewellery thief’s bottom
A POLICE investigation in Thailand has literally gotten to the bottom of the theft of valuable diamond.

Helen Cummings: extract from memoir Blood Vows
Three years after their wedding, Helen hoped a new life in a country town would be the turning point in her violent marriage.

NBN wars: Extract from Rules of Engagement by Kim Williams
Former Foxtel and News Corp chief executive's new book explores the dysfunctional regulatory regime that set the stage for the government's flawed ...

Resources last updated: 2/10/2016 2:31:33 PM