Sign up to create your own snipts, or login.

Public snipts » date The latest public date snipts.

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));
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by hongster on Mar 07, 2010 at 11:52 a.m. EST
  • 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.
    

    copy | embed

    0 comments - tagged in  posted by yvoictra on Jan 25, 2010 at 4:29 p.m. EST
  • 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 );
    }
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jan 22, 2010 at 3:28 p.m. EST
  • Getting actual date in Perl
    $DDMMYYHHMMSS = sprintf("%02d/%02d/%04d %02d:%02d:%02d", sub{($_[3],$_[4]+1,$_[5]+1900,$_[2],$_[1]),$_[0]}->(localtime(time())));
    

    copy | embed

    0 comments - tagged in  posted by yvoictra on Jan 14, 2010 at 6:40 p.m. EST
  • 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();
        });
    });
    

    copy | embed

    0 comments - tagged in  posted by boriscy on Nov 30, 2009 at 2:09 p.m. EST
  • 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
    

    copy | embed

    0 comments - tagged in  posted by gilbogger on Oct 27, 2009 at 9:47 p.m. EDT
  • 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;	
    }
    

    copy | embed

    0 comments - tagged in  posted by CorPao on Oct 19, 2009 at 3:43 p.m. EDT
  • PHP script file last modification data
    //echo script file last modification data
    echo date('d/m/y',filemtime($_SERVER['SCRIPT_FILENAME'])); 
    

    copy | embed

    0 comments - tagged in  posted by matt_dunckley on Oct 01, 2009 at 11:12 a.m. EDT
  • 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;
    ?>
    

    copy | embed

    0 comments - tagged in  posted by matt_dunckley on Oct 01, 2009 at 11:08 a.m. EDT
  • 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. 
    

    copy | embed

    0 comments - tagged in  posted by voyeg3r on Sep 29, 2009 at 8:35 a.m. EDT
  • Regex: Date format
    <?
    // Date must match format: mm/dd/yyyy
    if (!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $due_date))
      echo "Error !";
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Sep 15, 2009 at 3:38 p.m. EDT
  • Fecha en formato String YYYYMMDD
    DateTimeVariable.ToString("yyyyMMdd")
    

    copy | embed

    0 comments - tagged in  posted by ghporras on Sep 02, 2009 at 4:00 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by frankfarm on Aug 10, 2009 at 12:22 p.m. EDT
  • 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>
    

    copy | embed

    0 comments - tagged in  posted by isagoksu on Jul 31, 2009 at 1:41 p.m. EDT
  • Calculate age.
    <?php
    function age($dob) {
    	$age = date('Y') - date('Y', $dob);
    	if(date('md') - date('md', $dob) < 0) {
    		return --$age;
    	}
    
    	return $age;
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by hongster on Jul 26, 2009 at 10:19 p.m. EDT
  • Convert input to MySQL datetime.
    <?php
    date('Y-m-d H:i:s', strtotime($_POST['birthday']));
    ?>
    

    copy | embed

    0 comments - tagged in  posted by hongster on Jul 26, 2009 at 10:10 p.m. EDT
  • 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" />
    

    copy | embed

    0 comments - tagged in  posted by pixelclear on Jul 25, 2009 at 12:11 a.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by joeydi on Jul 16, 2009 at 2:08 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by siliconjones on Jul 08, 2009 at 4:02 p.m. EDT
  • 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>
    

    copy | embed

    0 comments - tagged in  posted by tbeseda on Jun 09, 2009 at 1:23 p.m. EDT
Sign up to create your own snipts, or login.