Get a date without time in SQL
--Extracts the date from the date time
CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime)
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 (or not, you can keep them private!)
CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime)
#!/bin/bash filename=$1 date=`date +%Y%m%d` usage () { echo "Usage: `basename $0` filename" } if [ -z "$filename" -a ! -f "$filename" ]; then usage exit 1 fi rev=0 backup="$filename.$date.$rev" while [ -f $backup ]; do let rev+=1 backup="$filename.$date.$rev" done cp $filename $backup exit $?
-- The syntax for pulling a certain part of a DATETIME is: -- -- CONVERT(date_type[(length)],expression[,style]) -- -- The available styles are as follows: -- -- NULL Jun 24 2001 9:48PM -- 1 06/24/01 -- 101 06/24/2001 -- 2 01.06.24 -- 104 24.06.2001 -- 108 21:48:00 -- 112 20010624 -- 121 2001-06-24 21:48:00.000 -- Some example usage: SELECT CONVERT(DATETIME,GETDATE(),112) as date -- Will output in YYYYMMDD format SELECT CONVERT(DATETIME,client.birthday,101) as birthday -- Will output in MM/DD/YYYY format
# wdays is an array with the days of the week # to exclude days (eg: wdays = [0,6] for sunday and saturday ) def calculate_working_days(d1,d2,wdays) diff = d2 - d1 holidays = 0 ret = (d2-d1).divmod(7) holidays = ret[0].truncate * wdays.length d1 = d2 - ret[1] while(d1 <= d2) if wdays.include?(d1.wday) holidays += 1 end d1 += 1 end diff - holidays end
d1 = Date.new( 2006, 12, 1 )
d2 = Date.new( 2007, 1, 15 )
weekdays = (d1..d2).reject { |d| [0,6].include? d.wday }
weekdays.length
sub nice_date { (my $date) = @_; ($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($date); $month+=1; $year+=1900; ($sec2, $min2, $hr2, $day2, $month2, $year2, $day_Of_Week2, $julianDate2, $dst2) = localtime(); $month2+=1; $year2+=1900; if($julianDate2==$julianDate and $year==$year2) { if($hr==$hr2) {print "a few moments ago";} elsif(($hr2-$hr)==1) {print "an hour ago";} elsif(($hr2-$hr)==2) {print "two hours ago}";} elsif(($hr2-$hr)==3) {print "three hours ago";} else {print "today";} } elsif($julianDate2==($julianDate+1) and $year==$year2) {print "yesterday";} elsif(($julianDate2-$julianDate)<=2 and $year==$year2) {print "two days ago";} elsif(($julianDate2-$julianDate)<=5 and $year==$year2) {print "this week";} else {print "$month/$day/$year";} }
ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY-HH24:MI'
strtotime("3 weeks thursday",mktime(0,0,0,11,1,$year)
#!/bin/bash grep -h '^Date:' * | perl -pe 's!^Date: !!' | perl -pe 's!^\w\w\w, !!' | perl -pe 's{\d{2}:\d{2}:\d{2}.*$}{}' | perl -pe 's!^\s+!!' | perl -pae '$_=sprintf("%.2d-%s-%s\n", @F)' | sort | uniq -c | sort -n
<?php $timezone = "the UK"; $time_diff = "0"; $alter = ($time_diff * 60 * 60); $date_today = date ("l F jS Y", time () + $alter); $time_now = date ("h:ia", time () + $alter); echo "It's currently <strong>$time_now</strong> on <strong>$date_today</strong> in <strong>$timezone</strong>."; ?>