Format a date for inserting into a MySQL database

From CodeCodex

Implementations[edit]

Java[edit]

	/**
	* This method formats the provided Date class object to a format for entering into a MySQL database
	*/
	public static String sqlDateTime(java.util.Date date) {
		
		java.text.SimpleDateFormat formatter;
		formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formatter.format(date);
		
	}

Ruby[edit]

time = Time.now
mysql_date_string = time.strftime("%Y-%m-%d %H:%M:%S")