Calculate Last Day of Last Month
DateAdd("d", -1.0 * DatePart("d", Today), Today)
11332 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
DateAdd("d", -1.0 * DatePart("d", Today), Today)
DateAdd("D", -1.0 * DatePart("D", Today) + 1, Today)
DateAdd("D", -1.0 * DatePart("D", Today) + 1, DateAdd("m", -1, Today))
public static double ToDouble(DateTime what) { return BitConverter.ToDouble(BitConverter.GetBytes(what.Ticks), 0); } public static DateTime ToDateTime(double what) { return new DateTime(BitConverter.ToInt64(BitConverter.GetBytes(what), 0)); }
string myTime = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"); Console.WriteLine(myTime);
public struct SystemTime { public ushort Year; public ushort Month; public ushort DayOfWeek; public ushort Day; public ushort Hour; public ushort Minute; public ushort Second; public ushort Millisecond; }; [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)] public extern static void Win32GetSystemTime(ref SystemTime st); [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)] public extern static bool Win32SetSystemTime(ref SystemTime st); .... public static void Test() { SystemTime newTime = new SystemTime(); newTime.Year = (ushort)2005; newTime.Month = (ushort)12; newTime.Day = (ushort)2; newTime.Hour = (ushort)12; //UTC time (if you are in UTC+2 zone then you'll put here: time - 2h) newTime.Minute = (ushort)42; newTime.Second = (ushort)11; Win32SetSystemTime(ref newTime); }
=System.DateTime.ParseExact(Parameters!lic_period_start_date.Value,"dd/MM/yyyy",System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString("yyyyMMdd")
module ActiveRecord module ConnectionAdapters class ColumnWithIdentity def cast_to_time(value) return value if value.is_a?(Time) or value.is_a?(DateTime) time_array = ParseDate.parsedate(value) time_array[0] ||= 2000 time_array[1] ||= 1 time_array[2] ||= 1 Time.send(Base.default_timezone, *time_array) rescue DateTime.new(*time_array[0..5]) rescue nil end def cast_to_datetime(value) if value.is_a?(Time) or value.is_a?(DateTime) if value.year != 0 and value.month != 0 and value.day != 0 return value else return Time.mktime(2000, 1, 1, value.hour, value.min, value.sec) rescue nil end end return cast_to_time(value) if value.is_a?(Date) or value.is_a?(String) rescue nil value end end end end
import time class datetime(object): def __init__(self, *argv): self.t = time.struct_time(argv+(0,)*(9-len(argv))) # append to length 9 def __getattr__(self, name): try: i = ['year', 'month', 'day', 'hour', 'minute', 'second', 'weekday'].index(name) return self.t[i] except: return getattr(self.t, name) def __len__(self): return len(self.t) def __getitem__(self, key): return self.t[key] def __repr__(self): return repr(self.t) def now(self=None): return datetime(*time.localtime()) now = staticmethod(now) def strftime(self, fmt="%Y-%m-%d %H:%M:%S"): return time.strftime(fmt, self.t)
# here it works like datetime.datetime() >>> t = datetime.now() >>> t.year, t.month, t.day (2006, 3, 13) >>> t.hour, t.minute, t.second (23, 3, 28) # but also works like localtime() >>> t (2006, 3, 13, 23, 3, 28, 0, 72, -1) >>> t.tm_year, t[0] (2006, 2006) >>> mktime(t) 1142265808.0 # good default for strftime (= ctime) >>> t.strftime() '2006-03-13 23:03:28'
>>> import datetime >>> now = datetime.datetime(2003, 8, 4, 12, 30, 45) >>> print now 2003-08-04 12:30:45 >>> print repr(now) datetime.datetime(2003,8,4,12,30,45) >>> print type(now) <type 'instance'> >>> print now.year, now.month, now.day 2003 8 4 >>> print now.hour, now.minute, now.second 12 30 45
datetime.datetime(2004,1,1).now() # work for any version
datetime.datetime.now() # python 2.3+
def now(self=None):
"Return the current date and time as a datetime."
now = t.localtime()
return datetime(now[0],now[1],now[2],now[3],now[4],now[5])
now = staticmethod(now)