ARCHIVES: August 2011

Common DateTime Formats

Tri Nguyen | August 03, 2011 | ADD COMMENT

The following are some common Formats for DateTime object. Assuming, we have a DateTime object declared "m_date" and today is January 14, 2011.

DateTime m_date = DateTime.Today;
Response.Write(m_date.ToString("MMMM d, yyyy"));
//January 14, 2011

Response.Write(m_date.ToString("MMM. d, yyyy");
//Jan. 14, 2011

Response.Write(m_date.ToString("MM/dd/yyyy");
//01/14/2011

Response.Write(m_date.ToString("M/d/yyyy");
//1/14/2011

Response.Write(m_date.ToString("MM-dd-yyyy");
//01-14-2011

Response.Write(m_date.ToString("MM-dd-yy");
//01-14-11
Notice: when using "MM" or "dd" in the format string, it'll always output two digits month or day. Leading zero will be added if the day or month has only a single digit such as January or any day less than 10.

References

ALTER TABLE Statement

Tri Nguyen | August 01, 2011 | ADD COMMENT
ADD A COLUMN IN A TABLE
ALTER TABLE table_name
ADD column_name datatype default value
Example:
ALTER TABLE users
ADD email nvarchar(50) default N''
This example add an email column to the users table and also set its default value empty string. Setting default value is relatively important; otherwise, it'll result in error if the users table currently has existing records.
DELETE A COLUMN IN A TABLE
ALTER TABLE table_name
DROP COLUMN column_name

CHANGE THE DATATYPE OF A COLUMN IN A TABLE
ALTER TABLE table_name
ALTER COLUMN column_name datatype