Public
snipts » date
showing 1-20 of 38 snipts for date
-
∞ Determine the earliest business day, taking business hour into consideration.
<?php function next_business_date() { $min = time(); // Past cut-off time, make it the next day. if (date('H', $min) >= '17') { $min += 86400; // +24 Hours } // If it falls on weekend, make it Monday. $day_of_week = date('N', $min); if ($day_of_week == '6') { $min += 172800; } elseif ($day_of_week == '7') { $min += 86400; } return strtotime(date('Y-m-d', $min)); } ?>
-
∞ Converting from date to epoch time
#!/usr/bin/perl use Time::Local $time = timelocal($sec,$min,$hour,$mday,$mon,$year); $time = timegm($sec,$min,$hour,$mday,$mon,$year); # Allowed range values # * day of the month: 1..31 # * month: 0..11 (0 = January, 1 = February, etc) # * year: # o If value>999: the value is interpreted as the actual year # o If value is 100..999: the value is interpreted as an offset #from 1900 (for example, 199 is considered year 2099) # o If value is 0..99: the value is interpreted based on the current year: if the current year is in the second half of the century #(for example 1970), then the values in the range 50..99 are considered of be in the current century and the values in the range 0..49 are in the next century. If the current year is in the first half of the century (for example 2007), then the range 0..49 is interpreted as values in the current century and the range 50..99 is interpreted as years from the #previous century.
-
∞ Dates Samples
<?php $currDate = date('Y-m-d h:i:s'); // convert timestamp from mysql $nextReviewDt = date('F d, Y',strtotime($nextReviewDt)); // Add 30 days $CommentStartDt = date('m/d/Y'); $CommentEndDt = date('m/d/Y', mktime(0,0,0,date("m"),date("d")+30,date("Y"))); // add 30 days // convert year to 4 digits if ($y > 60) $y = '19'.$y; else $y = '20'.$y; // split if there are slash or dash list($m, $d, $y) = split('[/|-]', $iDate); if (preg_match("/-/", $iDate)) list($m, $d, $y) = split('-', $iDate); else if (preg_match("/\//", $iDate)) list($m, $d, $y) = split('/', $iDate); $specDate = mktime(0, 0, 0, $m, $d, $y); $numOfDays = (time() - $specDate) / (24 * 60 * 60); // convert date from mysql db if (preg_match("/(.*)Dt$/", $dbDate)) $dbDate = date("M d, Y h:ia", strtotime($dbDate)); // output dates - walk the days $startDt = '2009-01-04'; $endDt = date('Y-m-d'); while ($startDt != $endDt) { echo "$startDt <br/>"; // increment the day $startDt = strtotime(date("Y-m-d", strtotime($startDt)) . " +1 day"); // convert back to readable format $startDt = date("Y-m-d",$startDt); } function count_days( $a, $b ) { // First we need to break these dates into their constituent parts: $gd_a = getdate( $a ); $gd_b = getdate( $b ); // Now recreate these timestamps, based upon noon on each day // The specific time doesn't matter but it must be the same each day $a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] ); $b_new = mktime( 12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year'] ); // Subtract these two numbers and divide by the number of seconds in a // day. Round the result since crossing over a daylight savings time // barrier will cause this time to be off by an hour or two. return round( abs( $a_new - $b_new ) / 86400 ); }
-
∞ Getting actual date in Perl
$DDMMYYHHMMSS = sprintf("%02d/%02d/%04d %02d:%02d:%02d", sub{($_[3],$_[4]+1,$_[5]+1900,$_[2],$_[1]),$_[0]}->(localtime(time())));
-
∞ date datetime picker jQuery UI for Rails
$(document).ready(function() { // Define the dateFormat for the datepicker $.datepicker._defaults.dateFormat = 'dd M yy'; /** * Sets the date for each select with the date selected with datepicker */ $('input.ui-date-text').live("change", function() { var sels = $(this).siblings("select:lt(3)"); var d = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $(this).val() ); $(sels[0]).val(d.getFullYear()); $(sels[1]).val(d.getMonth() + 1); $(sels[2]).val(d.getDate()); }); /** * Replaces the date or datetime field with jquey-ui datepicker */ $('.date, .datetime').each(function(i, el) { var input = document.createElement('input'); $(input).attr({'type': 'text', 'class': 'ui-date-text'}); // Insert the input:text before the first select $(el).find("select:first").before(input); $(el).find("select:lt(3)").hide(); // Set the input with the value of the selects var values = []; $(input).siblings("select:lt(3)").each(function(i, el) { var val = $(el).val(); if(val != '') values.push(val); }); if( values.length > 1) { d = new Date(values[0], parseInt(values[1]) - 1, values[2]); $(input).val( $.datepicker.formatDate($.datepicker._defaults.dateFormat, d) ); } $(input).datepicker(); }); });
-
∞ little date dealy for converting mysql date fomats to mm/yy/dd
$dt = '0000-00-00 00:00:00'; ".substr($dt,5,2)."/".substr($dt,8,2)." //dd/mm ".substr($dt,11,2).":".substr($dt,14,2)." //hh:mm
-
∞ date in italian format
function today() { var dt= new Date(); dt.setDate(dt.getDate()); var yyyy = dt.getFullYear(); var mm = ('0' + parseInt(dt.getMonth()+1).toString()).slice(-2); var dd = ('0' + dt.getDate().toString()).slice(-2); return dd+'/'+mm+'/'+yyyy; }
-
∞ PHP script file last modification data
//echo script file last modification data echo date('d/m/y',filemtime($_SERVER['SCRIPT_FILENAME'])); -
∞ echo days in this month
<? //echo days in this month //set up date variables $d_date = date('d', time()); $M_date = date('M', time()); $m_date = date('m', time()); $y_date = date('y', time()); $Y_date = date('Y', time()); $days_in_this_month = date( "d", mktime(0, 0, 0, $m_date + 1, 0, $Y_date) ); echo $days_in_this_month; ?>
-
∞ bash month test
[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'fim do mês' # o trecho antes da dupla igualdade retorna o mês do dia de amanhã, # já o trecho após a dupla igualdade retorna o mês do dia de hoje, caso # # sejam diferentes o bash avisa que você está no fim do mês.
-
∞ Regex: Date format
<? // Date must match format: mm/dd/yyyy if (!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $due_date)) echo "Error !";
-
∞ Fecha en formato String YYYYMMDD
DateTimeVariable.ToString("yyyyMMdd")
-
∞ my oft-preferred PHP date format, which is 4-digit year dot 2-digit month 2-digit day dot 2-digit hour (military time) 2-digit minute
Y\.md\.Hi
-
∞ Shows svn check ins for a specific user in a certain date range.
$ svn log -r {2009-07-09}:{2007-08-17} | grep -a3 <username>
-
∞ Calculate age.
<?php function age($dob) { $age = date('Y') - date('Y', $dob); if(date('md') - date('md', $dob) < 0) { return --$age; } return $age; } ?>
-
∞ Convert input to MySQL datetime.
<?php date('Y-m-d H:i:s', strtotime($_POST['birthday'])); ?>
-
∞ Well Formed Meta Tags
<meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta name="abstract" content="" /> <meta http-equiv="last-modified" content="Mon, 1 Jan 2009 12:00:00 -0700" />
-
∞ vb function to turn datetime
Function TimeAgo(dtField) days = DateDiff("d", dtField, Now) If days > 365 Then months = DateDiff("m", dtField, Now) years = DateDiff("yyyy", dtField, Now) monthsAdjust = months - (years)*12 If years = 1 Then ago = "Expired 1 year and " & monthsAdjust & " months ago" Else ago = "Expired " & years-1 & " years and " & monthsAdjust & "months ago" End If ElseIf days > 30 Then months = DateDiff("m", dtField, Now) If months = 1 Then ago = "Expired " & months & " month ago" Else ago = "Expired " & months & " months ago" End If Else ago = "Expired " & days & " days ago" End If TimeAgo = ago End Function
-
∞ Toucher - Changes file and folder modified date to now
on open these_items repeat with i from 1 to the count of these_items set this_item to (item i of these_items) set the item_info to info for this_item if folder of the item_info is true then process_folder(this_item) else process_item(this_item) end if end repeat end open -- this sub-routine processes folders on process_folder(this_folder) do shell script "touch \"" & POSIX path of this_folder & "\"" set these_items to list folder this_folder without invisibles repeat with i from 1 to the count of these_items set this_item to alias ((this_folder as text) & ¬ (item i of these_items)) set the item_info to info for this_item if folder of the item_info is true then process_folder(this_item) else process_item(this_item) end if end repeat end process_folder -- this sub-routine processes files on process_item(this_item) do shell script "touch \"" & POSIX path of this_item & "\"" end process_item
-
∞ show content based on date
<script type="text/javascript"> var myDate=new Date(); myDate.setFullYear(2009,5,7); var today = new Date(); if (today>myDate){document.getElementById('hidden').style.display = 'none';} </script>



Python Cookbook