Get Week number (french culture)
public static int weekNumber(DateTime dt) { CultureInfo culture = CultureInfo.CurrentCulture; int intWeek = culture.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); return intWeek; }
12388 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
public static int weekNumber(DateTime dt) { CultureInfo culture = CultureInfo.CurrentCulture; int intWeek = culture.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); return intWeek; }
enum EngineType { unknow, access, db2, mysql, odbc, oledb, oracle, postgre, sqlserver } string cnxTypeString = "mysql"; EngineType cnxTypeEngine = EngineType.unknow; if (Enum.IsDefined(typeof(EngineType), cnxTypeString)) { cnxTypeEngine = (EngineType) Enum.Parse(typeof(EngineType), cnxTypeString, true); }
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, IS_NULLABLE, SUBSTR(COALESCE(COLUMN_DEFAULT, ''), 1, 8) = 'nextval(' AS IS_AUTOINCREMENT, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'xxxxxxxx' ORDER BY ORDINAL_POSITION
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, IS_NULLABLE, COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') AS IS_AUTOINCREMENT, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'xxxxxxxx' ORDER BY ORDINAL_POSITION
/// <summary> /// Algorithm for calculating the date of Easter Sunday /// (Meeus/Jones/Butcher Gregorian algorithm) /// http://en.wikipedia.org/wiki/Computus#Meeus.2FJones.2FButcher_Gregorian_algorithm /// </summary> /// <param name="year">A valid Gregorian year</param> /// <returns>Easter Sunday</returns> public static DateTime EasterDate(int year) { int Y = year; int a = Y % 19; int b = Y / 100; int c = Y % 100; int d = b / 4; int e = b % 4; int f = (b + 8) / 25; int g = (b - f + 1) / 3; int h = (19 * a + b - d - g + 15) % 30; int i = c / 4; int k = c % 4; int L = (32 + 2 * e + 2 * i - h - k) % 7; int m = (a + 11 * h + 22 * L) / 451; int month = (h + L - 7 * m + 114) / 31; int day = ((h + L - 7 * m + 114) % 31) + 1; DateTime dt = new DateTime(year, month, day); return dt; }
SET IDENTITY_INSERT MyTable ON; INSERT INTO MyTable (MyIdentityField, MyFirstField, MySecondField) VALUES (12345, 'ABCDE', 'etc...'); SET IDENTITY_INSERT MyTable OFF;
CONVERT(DATETIME, 'yyyymmdd', 112)
{d 'yyyy-mm-dd'}
using System.Text.RegularExpressions; public class MyClass { public static void Main() { string text = "the quick red fox jumped over the lazy brown DOG."; System.Console.WriteLine("text=[" + text + "]"); string result = Regex.Replace(text, @"\w+", new MatchEvaluator(MyClass.CapText)); System.Console.WriteLine("result=[" + result + "]"); System.Console.ReadLine(); } static string CapText(Match m) { string temp = m.ToString(); temp = char.ToUpper(temp[0]) + temp.Substring(1, temp.Length - 1).ToLower(); return temp; } }
DateTime myDate; myDate = System.DateTime.ParseExact("20050802", "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
string myString = myDate.ToString("yyyyMMdd");