Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my string for getting DateTime is like this:
C#
string myDate = System.DateTime.Now.ToString("MM/dd/yyyy");

If I want to obtain all values of dates of month, how can I exclude the day from above string.
Please help with the code.

With regards,
bishnu
Posted
Updated 3-Nov-11 1:11am
v2

whatever you will write in format string will be extracted from the date like.

C#
System.DateTime.Now.ToString("MM yy");
System.DateTime.Now.ToString("MMM yyyy");
System.DateTime.Now.ToString("MM/yyyy");
 
Share this answer
 
try as follows:
DateTime myDateTime = DateTime.Now;
       string month = myDateTime.Month.ToString();
       string year = myDateTime.Year.ToString();
 
Share this answer
 
use this
C#
string myDate = System.DateTime.Now.ToString("MM yy");
 
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