• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

DateTime Format YYYYmmDD

How do I get a DateTime object in format YYYYmmDD.
E.g. for Jan 2, 2013 -> 20130102
  • 2
3 Solutions
gt2847cSr. Security ConsultantCommented:
This link gives you all of the formats

This should also do it:

From MSN:

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.
gt2847cSr. Security ConsultantCommented:
A much simpler method:

var myInt = int.Parse(myDateTimeVar.ToString("yyyyMMdd"));
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now