Parse string pattern into Date in Flex - apache-flex

Is there some way in flex to parse strings to date. I want it to support custom formats similar to 'dateformatter'. Using 'dateformatter' class we can parse date object in various string formats as specified by 'formatString property'. I want it other way round, from string to date. The parse method 'Date.parse(my_string)' does string parsing but for a very limited set of formats. Can't we have something similar to following, where user can specify his/her own formats.
someformatter.formatString = 'HH::MM::SS' ;
mydate = someformatter.formatTodate('23::56:34');
Will 'parseDateString' method of dateformatter be useul here?
Thanks in advance.

You can use
DateField.StringToDate()
This is static function of DateField class, and returns Date object.

Related

I want to display time as 09032014124008 rather than 9/3/2014 12:40:08 AM

I want to display time as 09032014124008 rather than 9/3/2014 12:40:08 AM
When I use DateTime.Now, the format is the latter one.
Kindly suggest how can I get it in the required format.
You can specify a custom format string on the call to .ToString()
For your example you would use:
DateTime.Now.ToString("MMddyyyyhhmmss")
Also see here for additional format string options

How can i Convert the DatePicker Input to string

I am using the following Codes to get the date from the date picker
objDD_ml.EffDate=(DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput).ToString
But it does not return the date... It returns like 'DateInput'
How can i use the code to get the value for Effdate as a correct format of date
Anyone please help me..
Whenever you want date into string and in specific format you can always apply following :
objDD_ml.EffDate = (
DirectCast(drv.Cells(3).FindControl("rdpEffDate"), RadDatePicker).DateInput
).ToString("dd/MM/yyyy")
Try to cast the FindControl object into the corresponding ASP control externally. Then access the value of that control and convert it to .ToString
I don't know what control you are using, but it should be something like below -
objDD_ml.EffDate = ((RadDatePicker)(drv.Cells[i].FindControl("rdpEffDate")).SelectedDate.Tostring;

best date regex mm/dd/yyyy

please help me to find the best regex for the dateformat mm/dd/yyy and m/d/yyyy.
i have tried different links but everyone has some problems. so please help me to solve this.
What is the MM/DD/YYYY regular expression and how do I use it in php?
http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5
http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html
Use one of the DateTime.TryParse overloads (or DateTime.TryParseExact if you want more control) to validate whether a string is a valid representation of a DateTime.
DateTime dt;
if(DateTime.TryParse(someInputString, out dt)
{
// it is valid and dt can be used
}
This would be a better approach than regular expressions - it is faster, well tested and will produce a valid DateTime object.
If you need a regular expression then something like this would work (for most cases, since it allows 31st of February).
(0?\d|1[012])\/([012]?\d|3[01])\/\d{4}
Usually it is much better to use DateTime parsing for verifying date formats. Like DateTime.TryParseExact method. You can use the regular expression in the browser (in JavaScript) but you should really use DateTime parsing on the server side.

DateTime syntax reference

I understand there are no complete reference docs available for Razor as yet, but would like to know what the various date format options are. Such as:
DateTime.Now.Day
DateTime.Now.Month
DateTime.Now.Year
DateTime.Now.Date
DateTime.Now.TimeOfDay
DateTime.Now.AddDays(1)
etc etc
Is there a complete reference anywhere for DateTime?
How do I get just DD/MM/YYYY without 00:00:00 being appended for example?
The DateTime class is part of the .NET framework. See MSDN documentation.
To format dates, you can use the .ToString(string format) method:
#DateTime.Now.ToString("dd/MM/yyyy")
DateTime is actually a .NET type. The full documentation is available here: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
For your particular question you would want to use the ToShortDateString() method:
DateTime.Now.ToShortDateString()

Error converting date for Calendar in asp.net

I have written code for two checkboxes:
string sdate= Convert.ToDateTime(txtFromDate.Value);
string edate=Convert.ToDateTime(txtEndDate.Value);
I am getting the following error: "String was not recognized as a valid DateTime".
Well, it's reasonably clear: the input string wasn't in an appropriate format. I suggest that instead of using Convert.ToDateTime, you use DateTime.TryParseExact and specify the format string (or strings) that you expect the user to enter.
Using TryParseExact instead of just ParseExact means you can detect if the user has entered an incorrect date without an exception being thrown - and you should check for that. Basically the return value of TryParseExact indicates success or failure, and an out parameter is used to capture the parsed date/time on success.
What I hadn't noticed to start with is that you're then trying to assign a DateTime value to a string. That's not going to work - but we can't advise you on what you should be doing instead without knowing what you want to do with the data. I suspect you want to change sdate and edate to be DateTime variables instead.

Resources