<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: month code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 08:17:35 GMT</pubDate>
    <description>DZone Snippets: month code</description>
    <item>
      <title>Increment a date using Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5200</link>
      <description>This Ruby code converts a string into a date and increments the day, week, month, quarter or year.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def date_add(sdate='', unit='',i=0)&lt;br /&gt;&lt;br /&gt;  sdate[/(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+):(\d+)/]&lt;br /&gt;  iyear = $3.to_i; imonth = $2.to_i; iday = $1.to_i; ihour = $4.to_i; imin = $5.to_i; isec = $6.to_i&lt;br /&gt;  &lt;br /&gt;  case  unit&lt;br /&gt;    when 'days'&lt;br /&gt;      t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      t1 += (60 * 60 * 24 * i)&lt;br /&gt;    when 'weeks'&lt;br /&gt;      t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      t1 += (60 * 60 * 24 * 7 * i) &lt;br /&gt;    when 'months'&lt;br /&gt;      imonth += i&lt;br /&gt;      if imonth &lt; 12 then&lt;br /&gt;        t1 = Time.local(iyear,imonth+i,iday,ihour,imin,isec)&lt;br /&gt;      else&lt;br /&gt;        t1 = Time.local(iyear+=1,imonth -12,iday,ihour,imin,isec)&lt;br /&gt;      end&lt;br /&gt;    when 'quarter'&lt;br /&gt;      imonth += 3&lt;br /&gt;      if imonth &lt;= 12 then&lt;br /&gt;        t1 = Time.local(iyear,imonth,iday,ihour,imin,isec)&lt;br /&gt;      else&lt;br /&gt;        t1 = Time.local(iyear+=1,imonth - 12,iday,ihour,imin,isec)&lt;br /&gt;      end    &lt;br /&gt;    when 'years'&lt;br /&gt;      t1 = Time.local(iyear+i,imonth,iday,ihour,imin,isec)&lt;br /&gt;    else&lt;br /&gt;      raise 'not a valid date unit'&lt;br /&gt;  end&lt;br /&gt;  t1&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;date_add("17/03/2008 17:48:00",'months',2)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output: Sat May 17 17:48:00 +0100 2008&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 13:43:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5200</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Code to disable YUI calendar previous and next month links icons</title>
      <link>http://snippets.dzone.com/posts/show/5198</link>
      <description>This solution does not require modifying the yui source and works on YUI version 2.5.0. It will disable the next and previous arrows based on the out of bounds dates you specify with mindate and maxdate when you configure the calendar. Requires YUI dom and a namespace called your_app.&lt;br /&gt;&lt;br /&gt;1) attach an onRender event when you configure the calendar and before you call render&lt;br /&gt;&lt;br /&gt;&lt;code&gt;calendar.renderEvent.subscribe(YAHOO.your_app.calendar().initArrows, calendar);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;2) add the following function:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;YAHOO.your_app.calendar = function() {&lt;br /&gt;	&lt;br /&gt;	var addDays = function(date, days) {&lt;br /&gt;		return YAHOO.widget.DateMath.add(date, YAHOO.widget.DateMath.DAY, days);&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	var showPreviousArrow = function(cal) {&lt;br /&gt;		return showArrow(cal, cal.toDate(cal.cellDates[0]), 1);&lt;br /&gt;	};&lt;br /&gt;&lt;br /&gt;	var showNextArrow = function(cal) {&lt;br /&gt;		return showArrow(cal, cal.toDate(cal.cellDates[cal.cellDates.length-1]), -1);&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	var showArrow = function(cal, startingDate, step) {&lt;br /&gt;		if (!cal.isDateOOM(startingDate)) { //ie not overlapping&lt;br /&gt;			return !cal.isDateOOB(addDays(startingDate, (-1 * step)));&lt;br /&gt;		}&lt;br /&gt;		for (var i=0; (i * step) &lt; 7; i += step) { //iterate forwards for previous month check, backwards for next month check&lt;br /&gt;			var date = addDays(startingDate, i);&lt;br /&gt;			if (!cal.isDateOOM(date)) { //shortcut exit; as soon as we find an in month date we can supress the arrow&lt;br /&gt;				return false;&lt;br /&gt;			} else if (!cal.isDateOOB(date)) {&lt;br /&gt;				return true;&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		return false;&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	return {&lt;br /&gt;		initArrows: function(type, args, cal) {&lt;br /&gt;			if (!showPreviousArrow(cal)) {&lt;br /&gt;				hideArrow(cal, cal.Style.CSS_NAV_LEFT);&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;			if (!showNextArrow(cal)) {&lt;br /&gt;				hideArrow(cal, cal.Style.CSS_NAV_RIGHT);&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;	};&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 03 Mar 2008 20:57:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5198</guid>
      <author>robd (Rob Dupuis)</author>
    </item>
    <item>
      <title>Calculate last day of current Month</title>
      <link>http://snippets.dzone.com/posts/show/5183</link>
      <description>'Determines what the next month is based on today and subtracts 1 day from first day of next month. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'VB.NET&lt;br /&gt;Dim NextMonth As Integer&lt;br /&gt;Dim RptYear As Integer&lt;br /&gt;'Determine next month&lt;br /&gt;NextMonth = DatePart(DateInterval.Month, DateAdd(DateInterval.Month, +1, today))&lt;br /&gt;'Determine the year of the next month, in case you are going from Dec to Jan&lt;br /&gt;RptYear = DatePart(DateInterval.Year, DateAdd(DateInterval.Month, +1, today))&lt;br /&gt;'Subtract 1 day from the first day of next month to get this months last day&lt;br /&gt;Return DateAdd(DateInterval.Day, -1, DateValue(NextMonth.ToString &amp; "/1/" &amp; RptYear.ToString))&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 27 Feb 2008 19:13:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5183</guid>
      <author>bmowbray (Brian Mowbray)</author>
    </item>
    <item>
      <title>Formatting a date in XSLT</title>
      <link>http://snippets.dzone.com/posts/show/5118</link>
      <description>This template formats a date ie 060208171320 -&gt; 06-Feb-08T17:13:20&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  &lt;xsl:template name="FormatDate"&gt;&lt;br /&gt;    &lt;xsl:param name="DateTime" /&gt;&lt;br /&gt;    &lt;!-- new date format 2006-01-14T08:55:22 --&gt;&lt;br /&gt;    &lt;xsl:variable name="mo"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,3,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="day"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,5,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="year"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,1,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="hh"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,7,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="mm"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,9,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="ss"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,11,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:if test="(string-length($day) &amp;lt; 2)"&gt;&lt;br /&gt;      &lt;xsl:value-of select="0"/&gt;&lt;br /&gt;    &lt;/xsl:if&gt;&lt;br /&gt;    &lt;xsl:value-of select="$day"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="'-'"/&gt;&lt;br /&gt;    &lt;xsl:choose&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '01'"&gt;Jan&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '02'"&gt;Feb&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '03'"&gt;Mar&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '04'"&gt;Apr&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '05'"&gt;May&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '06'"&gt;Jun&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '07'"&gt;Jul&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '08'"&gt;Aug&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '09'"&gt;Sep&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '10'"&gt;Oct&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '11'"&gt;Nov&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '12'"&gt;Dec&lt;/xsl:when&gt;&lt;br /&gt;    &lt;/xsl:choose&gt;&lt;br /&gt;    &lt;xsl:value-of select="'-'"/&gt;&lt;br /&gt;&lt;br /&gt;    &lt;xsl:value-of select="$year"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="'T'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$hh"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="':'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$mm"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="':'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$ss"/&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;copied from http://snipr.com/1z833 [geekswithblogs.net] and modified to suit the date input format I used.</description>
      <pubDate>Fri, 08 Feb 2008 00:00:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5118</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>PHP : Obtener registros por mes</title>
      <link>http://snippets.dzone.com/posts/show/4535</link>
      <description>si tienes un campo de tipo time() y necesitas sacar los registros de un determinado mes.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$mes=2;//febrero&lt;br /&gt;$strquery="SELECT *&lt;br /&gt;FROM `tabla`&lt;br /&gt;WHERE month( from_unixtime( fecha ) ) = '$mes'";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Sep 2007 12:08:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4535</guid>
      <author>Ricardo (Ricardo m. Garc&#237;a)</author>
    </item>
    <item>
      <title>days in month</title>
      <link>http://snippets.dzone.com/posts/show/4397</link>
      <description>// returns number of days in specified month&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def days_in_month(month)&lt;br /&gt;  (Date.new(Time.now.year,12,31).to_date&lt;&lt;(12-month)).day&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Aug 2007 13:10:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4397</guid>
      <author>kelyar (Kelyarsky Evgeniy)</author>
    </item>
    <item>
      <title>Determining the Number of Days in a Month with Javascript</title>
      <link>http://snippets.dzone.com/posts/show/2099</link>
      <description>Essentially, writing some code to determine the number of days in a given month of a given year with javascript is not the worlds most difficult task. It is the type of exercise that one would expect to be given as a newbie developer during a lab or lecture. The solution normally involves determining if the month is February, an month with 30 days or a month with 31 days, then (if February) checking if the year is a leap year. All these tests add up, however, and add several lines of code to your .js file. They are also unnecessary!&lt;br /&gt;&lt;br /&gt;Apparently, the javascript Date function allows you to overflow the day number parameter that you pass, creating a date in the next month. Deliberately overflowing the day parameter and checking how far the resulting date overlaps into the next month is a quick way to tell how many days there were in the queried month. Here is a function that does this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function daysInMonth(iMonth, iYear)&lt;br /&gt;{&lt;br /&gt;	return 32 - new Date(iYear, iMonth, 32).getDate();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;N.B.: iMonth is zero based, so 0 represents January, 1 represents February, 2 represents March and 11 represents December. iYear is not zero based, this is the actual calendar year number. (2006 is actually 2006)&lt;br /&gt;&lt;br /&gt;Pray that the browser developers know the correct way to determine whether a year is a leap year! (It's more complicated than a simple mod 4 == 0) Here is a quote from Wikipedia's page on leap years: "The Gregorian calendar, the current standard calendar in most of the world, adds a 29th day to February in all years evenly divisible by 4, except for centennial years (those ending in '00'), which receive the extra day only if they are evenly divisible by 400. Thus 1600, 2000 and 2400 are leap years but 1700, 1800, 1900 and 2100 are not."&lt;br /&gt;&lt;br /&gt;To test this function, February in the years 2100, 2005, 2004, 2003, 2001, 2000 and 1999 should be checked. All of these should return 28, except for 2004 and 2000.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2100));"&gt;February 2100&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2005));"&gt;February 2005&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2004));"&gt;February 2004&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2003));"&gt;February 2003&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2001));"&gt;February 2001&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 2000));"&gt;February 2000&lt;/button&gt;&lt;br /&gt;&lt;button onclick="alert(daysInMonth(1, 1999));"&gt;February 1999&lt;/button&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;How does this function work? It is quite simple. When the Date() function is given a day number that is greater than the number of days in the given month of the given year, it wraps the date into the next month. The getDate() function returns the day of the month, starting from the beginning of the month that the date is in. So, day 32 of March is considered to be day 1 of April. Subtracting 1 from 32 gives the correct number of days in March!</description>
      <pubDate>Thu, 25 May 2006 12:02:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2099</guid>
      <author>Charlie (Stephen Martindale)</author>
    </item>
    <item>
      <title>DateTime: Simple date operations in javascript</title>
      <link>http://snippets.dzone.com/posts/show/932</link>
      <description>&lt;code&gt;&lt;br /&gt;/*&lt;br /&gt;### begin_: file metadata&lt;br /&gt;    ### &lt;region-file_info&gt;&lt;br /&gt;    ### main:&lt;br /&gt;    ###   - name : cfDateTime.js&lt;br /&gt;    ###     desc : |&lt;br /&gt;    ###         Simple date operations in jscript.&lt;br /&gt;    ###         This file is for use with windows scripting host.&lt;br /&gt;    ###     date : created="Thu 2005-12-01 11:57:38"&lt;br /&gt;    ###     last : lastmod="Thu 2005-12-01 12:18:57"&lt;br /&gt;    ###     lang : jscript&lt;br /&gt;    ###     tags : jscript javascript date time now month hour year cfDateTime&lt;br /&gt;    ### &lt;/region-file_info&gt;&lt;br /&gt;    */&lt;br /&gt;&lt;br /&gt;/// begin_: declare and init variables&lt;br /&gt;    var today       = new Date();&lt;br /&gt;    var strYear     = today.getFullYear();&lt;br /&gt;    var iMonth      = today.getMonth() + 1; // +1, we do NOT want zero-based month index&lt;br /&gt;    var iQuarter    = Math.ceil((iMonth / 12) * 4);&lt;br /&gt;    var iDay        = today.getDate();&lt;br /&gt;    var strDateOut  = "";&lt;br /&gt;&lt;br /&gt;/// begin_: leading zeropad single-digit numbers&lt;br /&gt;    iMonth = (iMonth &lt; 10)? "0" + iMonth : iMonth;&lt;br /&gt;    iDay = (iDay &lt; 10)? "0" + iDay : iDay;&lt;br /&gt;&lt;br /&gt;/// begin_: display output&lt;br /&gt;    strDateOut = strYear+"-"+ iMonth +"-"+iDay + " ";&lt;br /&gt;    WScript.Echo (strDateOut);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 02 Dec 2005 07:17:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/932</guid>
      <author>drefty (drefty)</author>
    </item>
    <item>
      <title>DateTime: generic date and time script in perl</title>
      <link>http://snippets.dzone.com/posts/show/927</link>
      <description>&lt;code&gt;&lt;br /&gt;### begin_: file metadata&lt;br /&gt;    ### &lt;region-file_info&gt;&lt;br /&gt;    ### main:&lt;br /&gt;    ###   - name : DateTime.pl&lt;br /&gt;    ###     desc : DateTime: generic date and time script in perl&lt;br /&gt;    ###     date : created="Thu 2005-12-01 10:04:52"&lt;br /&gt;    ###     last : lastmod="Thu 2005-12-01 10:04:59"&lt;br /&gt;    ### &lt;/region-file_info&gt;&lt;br /&gt;&lt;br /&gt;### begin_: initialize perl (optional)&lt;br /&gt;    use strict;&lt;br /&gt;    use warnings;&lt;br /&gt;&lt;br /&gt;### begin_: initialize DateTime values&lt;br /&gt;    my %dttime = ();&lt;br /&gt;    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);&lt;br /&gt;&lt;br /&gt;### begin_: initialize DateTime number formats&lt;br /&gt;    $dttime{year }  = sprintf "%04d",($year + 1900);  ## four digits to specify the year&lt;br /&gt;    $dttime{mon  }  = sprintf "%02d",($mon + 1);      ## zeropad months&lt;br /&gt;    $dttime{mday }  = sprintf "%02d",$mday;           ## zeropad day of the month&lt;br /&gt;    $dttime{wday }  = sprintf "%02d",$wday + 1;       ## zeropad day of week; sunday = 1;&lt;br /&gt;    $dttime{yday }  = sprintf "%02d",$yday;           ## zeropad nth day of the year&lt;br /&gt;    $dttime{hour }  = sprintf "%02d",$hour;           ## zeropad hour&lt;br /&gt;    $dttime{min  }  = sprintf "%02d",$min;            ## zeropad minutes&lt;br /&gt;    $dttime{sec  }  = sprintf "%02d",$sec;            ## zeropad seconds&lt;br /&gt;    $dttime{isdst}  = $isdst;&lt;br /&gt;&lt;br /&gt;### begin_: xnpDate print iso8601 version date&lt;br /&gt;    print "$dttime{year}-$dttime{mon}-$dttime{mday}\n";&lt;br /&gt;&lt;br /&gt;### begin_: xnpNow show system time&lt;br /&gt;    print "$dttime{year}-$dttime{mon}-$dttime{mday} $dttime{hour}:$dttime{min}:$dttime{sec} \n";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 02 Dec 2005 05:27:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/927</guid>
      <author>drefty (drefty)</author>
    </item>
  </channel>
</rss>
