DateTime Format YYYYmmDD

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

Accepted Solution

gt2847c earned 375 total points
ID: 39246074
This link gives you all of the formats

This should also do it:


Assisted Solution

Eamun earned 125 total points
ID: 39246085
From MSN:

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

This should shift the numbers to YYYYMMDD format.

Assisted Solution

gt2847c earned 375 total points
ID: 39246094
A much simpler method:

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why Does This Page Not Show Up? 4 24
how to read json value 2 31
Pagebreak issue while printing the aspx page 3 15
Adware on IIS hosted website 1 17
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

18 Experts available now in Live!

Get 1:1 Help Now