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

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

i get date in wrong format - need help

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :Windows Application

i get date from xml in this format:  `7/16/2010 (mm/dd/yyyy)`

i have in my program  `datetime val -  MyDate`.

and when i try to placing   `MyDate = Convert.ToDateTime(7/16/2010)` 

i got error.

how i can fix it ?

thank's in advance

View Complete Post

More Related Resource Links

How To Set a Date Format In GridView Using ASP.NET 2.0

A very common desire is to set a column of a gridview to display just the month, day and year of a DateTime type. The problem is the by default, the HtmlEncode property of the boundfield attribute (
The problem is that if this field is enabled, you can not pass format information to the boundfield control. That is, if you try the following code, you will not get the desired result.

How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


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

CalendarExtender wrong date from database



I'm about to go NUTS :)

I have 2 CalendarExtenders on page. And I want to show the date that I get from SQL SEVER:

select -> SELECT convert(datetime,  begin) as Begin, convert(datetime, end) as End FROM Table

The date field, on base,  is a char(8)  and the record is like YYYYMMDD. That's why I convert it to datetime.

But, on code behind when I do this :

CalendarExtender1.SelectedDate = DateTime.Parse(objDataEvento.Rows(0)(2))
CalendarExtender2.SelectedDate = DateTime.Parse(objDataEvento.Rows(0)(3)) 

Depend of the date, It's showing minus 1 day on page.

Like: If, on base, the date is 08/12/2010, on page it's showing 07/12/2010.

WHYYYYYYYYYYYY ??????????????? Cry Smile




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.

SharePoint Search returns wrong date

Hi i am running a Sharepoint 2010 enterprise search indexing a file folder structure with emails(.eml) and attachments(.doc(x), pdf, xls(x), ...). The search results shows a date like first full index time or something like that, but not the date of file creation or any other attributes of the file. My questions: - what may be the reason of the wrong date? - is there a possibility use another attribute for displaying that is more relevante? Please help Kind regards Werner Durrer    

How do I format a date time field in a CQWP to YY-MM-DD ?

Hi. I have been trying to get the date-time to look good for some time now, but have failed. I have a Content Query web part that picks up article pages from a page library. The pages contains a field called 'article date'. I want to show just the 'Title' and the 'Article date'. Doing this default gives me: My title 10-09-03 00:00:00 I want it to be: My title 10-09-03 Is this possible? I'm starting to realize that I probably have to edit the xsl styles for this webpart but if thats the answer, how do I do that? ThanksThomas Balkeståhl - Technical Specialist - SharePoint

Format Date in TextBoxFor

I've been trying to format the date in a view form in a textboxfor and it seems everything I try doesn't seem to work. I found this great partialview example but it doesn't work when applied to EditorFor. Again works great when using the DisplayFor HTML helper method but still spits out the time at the end when trying to format for a textbox.If anyone has any suggestions or answers I would be greatly appreciative.Jim

Date format for Year, Year-Month, and Date (Year-Month-Day) where input is not known

I have a requirement to capture historical events in a table. Now some events will have only Year, some Year/Month, and remaining where Date is known. We should be able to store them in the column and be able to sort etc. When publishing the information, we should be able to publish as was the input, Year only, Year-Month only, or Date. I looked at the newer Date data type. I can insert a 4 digit year, but on retrieving it is YYYY-01-01. I do not know if it has input YYYY or YYYY-MM-DD and is indeed a Date or a Year. I am trying to avoid saving the format information in another column or something. For sorting, when records have same Year, I would have another column to do relative sorting... So question is - what are my best options with SQL/Entity Framework combo. And what others have done, when encountering similar - if any. Thanks in advance. --Sharad 

how to change date format

Hi,   I am using Oracle 10g im my asp.net project. In my select query, i want to change the format to dd/mm/yyyy hh:mm:ss from mm/dd/yyy hh:mm:ss. The field datatype is date. How can i write a query for this?

Why can I not group by calculated field in Date format?

After migrating to SP2010 Foundation, I've discovered that for some reason I can't group a list by a calculated date field. Ex: Create a list with a date column A. Create another column B with a simple calculated date of [A]+1 and use the field format type 'date' Modify view to group the list by column B.  You're list will load, but when you attempt to expand one of the groups you'll be greated with an exception error. Why?? Am I doing something wrong? Note: You can group fine if the data type for column B is anything except 'date' format, but I really need to group items by a calulated date. Ultimately, what I'm trying to do is group my list items by week by calculating the end of the week using a simple formula =[Must ship by]+7-WEEKDAY([Must ship by])  then I want to gropu by the [Must Ship by] column like I always did in SP 2007, but now it errors out.  I also wanted to create my own timesheet template since the Fab 40 templates aren't available for 2010, but I can't really do that effectively without being able to group timesheet entries by week.  

How to get a date in ISO format in DataViewWebPart

Is it possible to get date in ISO format (2005-08-23T18:31:42Z) inside DataViewWebPart in SharePoint 2010? I am only able to get the date in my locale, which doesn't sort properly. In SharePoint 2007 there was no such problem, but in 2010 it is a very annoying one.

date format in excel using c#

i have a datagridview and one of the column is date with format dd/MM/yyyy HH:mm:ss but when i export to excel the date format become 'd/m/yy HH:mm' how can i format the column in excel with the date format 'dd/MM/yyyy HH:mm:ss' i am using below method Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass(); Excel._Worksheet oSheet;  oSheet = (Excel._Worksheet)oWB.Worksheets[1];

Need to convert query string(date - 09/15/2010) to a text format - yyyymmdd

I am fairly new to C # and need some assistance with a form page.  I have created a simple form that requires the user to select a beginning date and ending date.  I then pass the values to my code behind page via query strings.  I have them passing, but I need the format to be change to a different format.  Unfortunately the database does not use the standard date format.  It requires the date to be in a text format as YYYYMMDD.Form: <tr> <td> Beginning Date:</td> <td><asp:TextBox runat="server" ID="begDate"></asp:TextBox> <asp:Image ID="Image2" ImageUrl="~/images/calendar_schedulehs.png" runat="server" /></td> </tr> Code Behind: protected void createReport_Click(object sender, EventArgs e) { StringBuilder url = new StringBuilder("Report/TopCustomer.aspx?"); url.Append("BegDate=" + begDate.Text); url.Append("&EndDate=" + endDate.Text); url.Append("&Brnch=" + ddlLocation.SelectedValue); Response.Redirect(url.ToString()); Current URL: TopCustomer.aspx?BegDate=09/15/2010&EndDate=09/30/2010&Brnch=300I need to have the above URL change to:TopCustomer.aspx?BegDate=20100915&E

Sharepoint date calculations = WRONG

Can someone show me how to create a calculated column that displays the date only? I'm using the microsoft absence planner. I am simply trying to display a date without the time. I'm getting inconsistent results. Someone suggested that I simply add a day but that is not consistent. I created a calcualted column to show me the day that Sharepoint thinks the time value has. The results are disappointing to say the least someone suggested this formula since it seems to be always off by a day: StartDate is a calculated column = =DATE(YEAR([Start Time]),MONTH([Start Time]),DAY([Start Time]+1)) *sometimes this formula displays the right info, sometimes not The last column is just = Day_[Start Time] so I can try and figure out what is going on :( Attendance item      System Account      Other      6/28/2010 12:00 AM      6/29/2010      28 Attendance item      System Account      Jury Duty      9/29/2009 12:00 AM      9/30/2009      29 Attendance item      System Account      Jury Duty      9/29/2009 12:00 AM      9/30/2009 &nbs

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