Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

from date picker i am getting value on textbox ,, as month year ..

I want to separate that and store in onevariable ..

pelase suggest

March 2015
April 2016

these are the values are on my textbox .. i want to separte month and year
Posted
Updated 18-May-15 0:36am
v2
Comments
aarif moh shaikh 18-May-15 6:34am    
use substring() for it..
[no name] 18-May-15 7:04am    
Are you trying jquery code or c# ?

Try this for jquery date separation : click here

C#
string dateText = "March 2015";

DateTime dt;

if (DateTime.TryParseExact(dateText, "MMMM yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
    // get the month
    string month = dt.ToString("MMMM");

    // get the year as a string
    string yearText = dt.ToString("yyyy");

    // or get it as an int
    int year = dt.Year;
}
 
Share this answer
 
The DateTimePicker delivers you on the Property "Value" the selected Date as DateTime.
You only have to seperate from this Return-Value (DateTimePicker1.Value.Month or DateTimePicker1.Value.Year)
 
Share this answer
 
C#
string s = txtReviewStartDate.Text.Trim();
                string[] words = s.Split(' ');
                int month = DateTime.ParseExact(words[0].ToString(), "MMMM", System.Globalization.CultureInfo.InvariantCulture).Month;
                hdnFromMonth.Value = month.ToString();
                hdnFromYear.Value = words[1].ToString();


I tried like this , thanks eveyone for suggesting for this question . I solved my query with better way
 
Share this answer
 
use split with delimitter what you have in textbox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900