[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making Datetime give : MMYY

Posted on 2007-10-08
5
Medium Priority
?
1,303 Views
Last Modified: 2008-01-09
How would I setup DateTime to be :

mmyy

Cheers
0
Comment
Question by:directxBOB
5 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 20034976
Do you mean when displaying it?

DateTime t = ...
t.ToString( "MMyy" );
0
 
LVL 5

Expert Comment

by:jtarabay
ID: 20035046
See if this helps you...

using C = System.Console;
...
static void Main() {
   DateTime dateTime = DateTime.Now;
   C.WriteLine ("d = {0:d}", dateTime );  // mm/dd/yyyy
   C.WriteLine ("D = {0:D}", dateTime );  // month dd, yyyy
   C.WriteLine ("f = {0:f}", dateTime );  // day, month dd, yyyy hh:mm
   C.WriteLine ("F = {0:F}", dateTime );  // day, month dd, yyyy HH:mm:ss AM/PM
   C.WriteLine ("g = {0:g}", dateTime );  // mm/dd/yyyy HH:mm
   C.WriteLine ("G = {0:G}", dateTime );  // mm/dd/yyyy hh:mm:ss
   C.WriteLine ("M = {0:M}", dateTime );  // month dd
   C.WriteLine ("R = {0:R}", dateTime );  // ddd Month yyyy hh:mm:ss GMT
   C.WriteLine ("s = {0:s}", dateTime );  // yyyy-mm-dd hh:mm:ss (Sortable)
   C.WriteLine ("t = {0:t}", dateTime );  // hh:mm AM/PM
   C.WriteLine ("T = {0:T}", dateTime );  // hh:mm:ss AM/PM
 
   // yyyy-mm-dd hh:mm:ss (Sortable)
   C.WriteLine ("u = {0:u}", dateTime );  
 
   // day, month dd, yyyy hh:mm:ss AM/PM
   C.WriteLine ("U = {0:U}", dateTime );
 
   // month, yyyy (March, 2006)
   C.WriteLine ("Y = {0:Y}", dateTime );  
   C.WriteLine ("Month = " + dateTime.Month); // month number (3)
 
   // day of week name (Friday)
   C.WriteLine ("Day Of Week = " + dateTime.DayOfWeek);    
 
   // 24 hour time (16:12:11)
   C.WriteLine ("Time Of Day = " + dateTime.TimeOfDay);    
 
   // (632769991310000000)
   C.WriteLine("DateTime.Ticks = " + dateTime.Ticks);  
   // Ticks are the number of 100 nanosecond intervals since 01/01/0001 12:00am
   // Ticks are useful in elapsed time measurement.
   }
0
 

Author Comment

by:directxBOB
ID: 20039233
Sorry perhaps I should clear this up.

I am using SOAP at the moment, and i need to provide an expiry in the form of:

MMYY

Now I could make it an int, and have a method valid a 4 digit number is within the range, but most likely the best way to do it would be to have the user on the other end parse in an int of MMYY and send on DateTime which I can then handle and parse as I wish?

So how would I

parse an int 0112 into MMYY format.

and how would I reverse that

MMYY format to 0112
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 20048360
DateTime.Now.ToString("MMyy") should work. Whatever format you receive a valid date, get a date time object and use the ToString method to get the month and year.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 20064225
Err.. Hello? I said that two days ago!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question