#! /bin/sh

# daysinmonth.sh - determine the number of days in the month for arbitrary
# date.  Two methods are shown, both of which seem rebarbative.

# Paul DuBois
# paul@snake.net
# 1999-08-19

# change the date to whatever date you want to test
date="1996-2-3"

echo "Test date: $date"

mysql samp_db <<EOF
SELECT
	DAYOFMONTH(
		DATE_SUB(
			DATE_ADD(
				CONCAT(YEAR("$date"),"-",MONTH("$date"),"-1")
				,INTERVAL 1 MONTH)
			,INTERVAL 1 DAY)
	)
	,
	DAYOFMONTH(
		DATE_SUB(
			CONCAT(YEAR("$date")+IF(MONTH("$date")=12,1,0),"-",
				(MONTH("$date")%12)+1,"-1")
			,INTERVAL 1 DAY)
	)
;
EOF
