.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How Convert Datetime (YYYY/MM/dd HH:mm:ss) To yyyy-MM-dd

Posted By:      Posted Date: August 24, 2010    Points: 0   Category :ASP.Net


How do you write a date value to an XMLElement in .NET 3.5 XMLDocument object. 


 I am using the following:


DateTime orderDate = new DateTime();
orderDate = DateTime.Now; // 2010-08-24 16:45:46

string st = XmlConvert.ToString(orderDate, "yyyy-MM-dd");     // st="2010-08-24"
DateTime dt2 = XmlConvert.ToDateTime (st, "yyyy-MM-dd");   // dt2 = "2010-08-24 00:00:00"

I would like to remove the time section "00:00:00". I only need to write a date in the XML file with the following format :


Order date is defined like this in the xsd file : <xs:element name="OrderDate" type="xs:date"/>


Thanks for your support.

View Complete Post

More Related Resource Links

How to convert Date format from dd/MM/yyyy to mm/dd/yyyy in asp.net



         I am using a text box which captures the date from the datepicker and displays in dd/MM/yyyy format in asp.net using C#

When i try to pass this text box value into the DatTime variable i am getting the error as

"String was not recognized as a valid DateTime. "


my code goes like this

DateTime dt;




i tried to use Conver.ToDateTime() function but the same error is croping up..


Can any one plz suggest me on this.....Thnks in advance

"Out-of-Range" Error When Passing DateTime (DD/MM/YYYY) into Stored Procedure

Hi everybody, I hope some of you will be able to help me regarding this datetime problem. The query in the stored procedure doesn't accept DD/MM/YYYY format, although all dates are being saved in the format of DD/MM/YYYY hh:mm:ss. Example of query that throws the error: @sDate = '31/8/2010' @eDate = '1/9/2010' SELECT * FROM tb_Schedule where scheduledate >= @sDate and scheduledate <= @eDate  Error:  The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value FYI, the SQL Server 2005 is defaulted to British English(2057)for all logins and the DB server itself and my server Regional and Language is set to English (United Kingdom). Any help will be appreciated. Thank you very much.  

T-SQL 2005 datetime as Mmm-YYYY and proper Order By?

Hi I have datetime column in SQL 2005 table. I want to convert that date time into Mmm-YYYY format i.e. Jan-2010, May-2010, Dec-2010 and then proper ORDER BY in month ordering ( in my actual query I want data to be GROUP BY month & year) Table has OrderDate colmin with type datetime Query result output I am looking is : OrderDate       OrderDateMonthYYYY   ORDER BY too 2010-01-25     Jan-2010 2010-02-15     Feb-2010 2010-08-15     Aug-2010 Any T-SQL 2005 Pls…  

Create a datetime object as dd/mm/yyyy

Hi i want to create a datetime object in the way dd/mm/yyyy but the defualt behaviour of datetime object is mm/dd/yyyy. I want this because my user enters date in dd/mm/yyyy format and i want to apply different additions and subtrations on this format. I know how to display dates in different formats. 

Convert date in dd.mm.yyyy


Date on the page is displayed in the format mm.dd.yyyy, how to convert it to be displayed in the format  dd.mm.yyyy.

This is the code from the site:


whether it be something like this  <%# Convert. ??????  Eval("newsDate")%> 


Convert Date (dd-MM-YYYY) to (dd/MM/YYYY)


Dear Sir,

In my DB, there is 5000 date values are stored like "DD-MM-YYYY" Format in nvarchar datatype. For Example 18-10-2010

And when i convert into date format for the following purpose.

"Select * from tbl_master order by Convert(datetime,date_of_Appln,103)"

Its not working.

Can you help me to convert? or Can you help me to replace the "-" symbol to "/"?

Thanks in advance.



Asp.net Javascript Validation dd/mm/yyyy format


Hi experts,

 I am trying to validate two textbox (fromdate,todate)

should alert a message when Fromdate is more than Todate

I could find only mm/dd/yyyy format in most of google search.

please give me a script or assist how to do this.



Need Regular Expression for d/mm/yyyy hh:mm:ss

Hi everybody,i am stuck in generating a regular expresion for this typem/dd/yyyy hh:mm:ssbecause i am dealing with some date values, for example i have  date values like bellow, 3/29/2007 13:28:343/27/2007 17:12:36so i need to find out a regular expression type in order to validate this, i already got some regular expression string like this ,^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}$but this is working only for 03/29/2007but if i use 3/29/2007 it wont work , or if use 03/27/2007 17:12:36 still it wont work so i really need you guys help on this to generate my regular expression string thanksregrdssukavi

Convert XML DateTime to SQL DateTime

I have tried to convert XML datetime value to SQL datetime by executing the below statement, though I feel there might be some other way of converting the value in SQL server 2000. declare @TestXMLTime as varchar(50) set @TestXMLTime ='2010-01-01T00:00:07+05:30' select cast(left(@TestXMLTime,10)+' '+right(left(@TestXMLTime,19),8) as datetime)    

Insert DATE to database (format 'YYYY-MM-DD')

How can I insert BIRTHDATE into column in 'YYYY-MM-DD' format. This is my code, can anyone edit my code? Tnx String = "INSERT into concfile VALUES(BIRTHDATE('" & DateTimePicker1.Text & "', 'YYYY-MM-DD'))"

how can I make field with date in format: dd/mm/yyyy ?

I have in model:[DisplayName("Publication date")] [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] [Required(ErrorMessage = "Publication date is required.")] public DateTime publication_date { get; set; } And in view:<div> <%: Html.LabelFor(model => model.publication_date) %> </div> <div> <%: Html.TextBoxFor(model => model.publication_date, new { @class = "datepicker" })%> <%: Html.ValidationMessageFor(model => model.publication_date) %> </div> But when I write in this field date: 30/11/2009 I see validation error: The value '30/11/2009' is not valid for publication_date.

Display date as mm/dd/yyyy instead of yyyy-mm-dd

This should be a fairly simple question. On my performancepoint reports, I would like to return the date as 08/20/2010 as opposed to 2010-08-20. I tried to follow this guide, http://wills-blog.com/?p=93 , but it is outdated and does not seem to work in this situation. Could someone point me in the right direction?

How to use compare validator with dd/MM/yyyy format of date

Hi all,  I have a form of leave application that has 2 dates, start date and end date. now i'm using the dd/MM/yyyy format for the date entry and i need to Validate end date like end date must me greater than or equal to start date. i want to do that with compare validator but its not working properly because of the Date  formats controls are using.    Currently i'm using textbox with Calendar extender ajax toolkit control.    So please help me if anybody have some hints.    Thanks in advance.

Validation for dd mm yyyy dropdown list

Hi i have a form which asks for date of birth.please find below the code. <asp:DropDownList ID="ddlDay" runat="server"> </asp:DropDownList> &nbsp;<asp:DropDownList ID="ddlMonth" runat="server"> </asp:DropDownList> &nbsp;<asp:DropDownList ID="ddlYear" runat="server"> </asp:DropDownList> asp:CustomValidator ID="valDate" Text="*" runat="server"      ControlToValidate="ddlDay"  ValidationGroup="Group1" OnServerValidate="valDate_ServerValidate" ClientValidationFunction="valDate_ClientValidate"  ErrorMessage="Please enter a valid date of birth" Display="Dynamic" ForeColor=""  CssClass="validatorText" /> The dropdownlist is populated in code behind. The client and server validation code is,        function valDate_ClientValidate(source, args) {            var dd_id = document.getElementById("<%=ddlDay.ClientID %>");            var mm_id = document.getElementById("<%=ddlMonth.ClientID %>");   &nb

format date yyyy-MM-dd and remove 00:00:00

HiI have a very simple question.I retrive a date from my database and save it in a date variable Dim ShowDate As Date = dt.Rows(I)("ShowDate")The date look like this "2010-09-11 09:48:00"now i just want to format it so it only shows the date "2010-09-11"I have tried the following ShowDate = ShowDate.ToString("yyyy-MM-dd")but that returns "2010-09-11 00:00:00"any idea what I am doing wrong?

Date Conversion from dd/mm/yyyy to yyyy-mm-dd

Hi guys,   I need a expression to convert date format from dd/mm/yyyy to yyyy-mm-dd by using SUBSTRING, FINDSTING  COLUMN NAME: ExtractionDate   I tried something like this to get year first and later on to add mm and DD, but its not working   SUBSTRING(@[User::ExtractionDate], FINDSTRING((@[User::ExtractionDate], "/", 2)),4)   Any help much appreciated   Thanks,        

is there any way to work with date in this format: dd/MM/yyyy hh:mm

hi is there any way to work with date in this format: `dd/MM/yyyy hh:mm` (without second) i see only this format: `dd/MM/yyyy hh:mm:ss` i need that i can see in this format and to run search between date & time in this format i work on access-2007 and C# thank's in advance
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend