Say the current date is 1st Mar 2010, I want to display it like this...
20100301 so like first 4 digits = year, 2 digits = Month, 2 digits = day
is there an easy way to do this?
The ToString() method of the DateTime class is used to convert a DateTime date object to string format. The method takes a date format string that specifies the required string representation.
Create a custom date formatPress CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type. You can adjust this format in the last step below.
Use datetime. strftime(format) to convert a datetime object into a string as per the corresponding format . The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.
Create a custom date or time formatOn the Home tab, click the Dialog Box Launcher next to Number. You can also press CTRL+1 to open the Format Cells dialog box. In the Category box, click Date or Time, and then choose the number format that is closest in style to the one you want to create.
use format
yourdatetimeObj.ToString("yyyyMMdd");
Ref: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With