Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Thursday, March 29, 2012

Set DateTime format

Can I set that DateTime format accept "dd/MM/yyyy" format of date?Hello, Where do you want to set them ? in a textbox, where ?

regards.
Hello, what you need to do is to convert the string into a dateTime right ?

Check this link please:
DateTime Constructors

regards.
User will enter date in format "dd/MM/yyyy" and I need to convert that user input into DateTime, without changing CultureInfo.

??
Yes


Edited by haidar_bilal - Please place your code within< code > and < /code > tag. Thank you.

I found solution. U put this in Application_BeginRequest method in Globa.asax.cs

DateTimeFormatInfo dtf = new DateTimeFormatInfo();
dtf.ShortDatePattern = "dd/MM/yyyy";
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-GB");
culture.DateTimeFormat = dtf;
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

CurrentCulture is still en-GB and datetime format is dd/MM/yyyy
Glad you solved your problem.

regards.

Tuesday, March 13, 2012

Set property for datetime field

How do I set the property for a datetime field? The get works (compiles; don't know yet if it works) with .ToString(). The set doesn't compile with just "= value".

public string CreateDate
{get{return issuesCurrentRow.CreateDate.ToString();}
set{issuesCurrentRow.CreateDate = value;}}

And I assume that datetimes are handled as strings??

I've been looking through my books and online; haven't found any info yet. I'm sure it's a simple answer...

Thanks,
Sherilyn

set{issuesCurrentRow.CreateDate = DateTime.Now;}}

will compile. And I do want to use the current date/time on the system. My "set" value is going into the database, so this seems right.

I'd like to hear any objections. Thanks.
It is because you are assigning string value to a datetime data type.

Try this...

public DateTime CreateDate
{
get
{
return issuesCurrentRow.CreateDate;
}
set
{
issuesCurrentRow.CreateDate = value;
}

}

and change the value to string when you call the property.

Thanks,
Sridhar!!