Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

DateTime Format YYYYmmDD

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

This should also do it:

myDateTimeVar.ToString("yyyyMMdd")
0
 
EamunCommented:
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
 
gt2847cCommented:
A much simpler method:

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

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