Solved

DateTime Format YYYYmmDD

Posted on 2013-06-13
3
564 Views
Last Modified: 2013-06-14
How do I get a DateTime object in format YYYYmmDD.
E.g. for Jan 2, 2013 -> 20130102
0
Comment
Question by:allelopath
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
gt2847c earned 375 total points
Comment Utility
This link gives you all of the formats

This should also do it:

myDateTimeVar.ToString("yyyyMMdd")
0
 

Assisted Solution

by:Eamun
Eamun earned 125 total points
Comment Utility
From MSN:
http://msdn.microsoft.com/en-us/library/efez4684.aspx

When you return the numbers, do you still need them as an int?
You can use:
DateTime currentDT = DateTime.now;
int dtObject = currentDT.Year * (Math.Pow(10,4)) + currentDT.Month * (Math.Pow(10,2) + currentDT.Day

This should shift the numbers to YYYYMMDD format.
0
 
LVL 9

Assisted Solution

by:gt2847c
gt2847c earned 375 total points
Comment Utility
A much simpler method:

var myInt = int.Parse(myDateTimeVar.ToString("yyyyMMdd"));
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now