Spiga



Showing posts with label php code. Show all posts
Showing posts with label php code. Show all posts

Determining Last Day of a Given Month

It is often useful to determine what the last day of a given month is. Although a lookup table could tell you what the actual day is (although you would have to still calculate February based on leap years), it is often useful to have an actual time stamp for that day.

Fortunately, through the use of mktime() this is not difficult. This function accepts the following variables in order: hour,minute,second,month,day and year. The powerful part is that mktime() automatically determines zero or negative number for you correctly.

Therefore, whereas entering a month of 3 (March) and a day of 1 returns a stamp for March 1' entering a month of 3 (March) and a day of 1 returns a stamp for February.

Code below demonstrate how to take advantage of mktime() in calculating last-day-of-month time stamps.




//set the default timezone to US/Eastern
date_default_timezone_set('US/Eastern');

//Will return a timestamp of the last day in a month for a specified year
function last_day($month, $year) {

//Use mktime to create a timestamp one month into the future, but one day //less.
//Also make the time for almost midnight, so it can be used as an 'end of //month' boundary
return mktime(23, 59, 59, $month + 1, 0, $year);

}

//Determine the last day for february, 2006
$stamp = last_day(2, 2006);

//Output the result, it will be : 28
echo '

The last day for February in 2006 is: ',date('d', $stamp) , '

';

?>

Time And Date in PHP5

Application that deal with are forever present, especially in web-based application: times of form submittals, user input such as date of birth, and the updating and removal of pages when out of date are just a few examples. Though potentially complicated, the date extensions in PHP are relatively simple and straightforward.

This lesson deals mainly with the core date and time functions. These function provide all basic for time manipulation which is retrieving, formatting, and converting. One other extension, the calendar functions, is devoted to conversion between different calendar systems, such as converting dates between the Gregorian and Jewish calendars. After this you can see the fucntion cal_to_jd() and cal_from_jd() on my Quick code below.

Subject beyond the scope of this chapter is that of schedule or calendar management, such as meeting and event scheduling. An extension is available, called MCAL, which does provide such functionality. for more information, see http://php.net/mcal.

To fully utilize the time functionality of PHP, you must understand how PHP measures time. For PHP, time is measured as the number of seconds since January 1, 1970, theUNIX epoch.
Hence any moment in time is store as a simple integer. Time, when stored this way, is often referred to as a time stamp. As you will see, many functions either return a time stamp or use a time stamp as a parameter. You must be careful however, when reading documentation or code comments. Depending on context, the term time stamp can also be used in its more generic sense: a time at which something occurs. For example, when referring to web server log files, the time at which an event is logged is reffered to as a time stamp.

This i add a Quick hits of function in time and date in PHP

Get the time stamp for the current time:

$timestamp = time();

Taking no parameter, this function returns the time stamp of the current time-that is,when time() is called.



Get the current time stamp to the microsecond resolution:

$result = microtime($format);

retun the UNIX time stamp but resolved to microseconds in accuracy. If $format is false, the default, the time is returned as the string "seconds microseconds" with the seconds portion the same as that returned by time(), and microseconds as a fraction of a second.If $format is true, the time is returned as a floating point number.


Create a time stamp for a specified date and time:

$timestamp =mktime($hour,$minute,$second,$month,$day,$year);

Return a time stamp that corresponds to the specified time and date.


Format the specified time:


$string = date($format,$timestamp);

Return a string representing the given time stamp based on the specified format. If $timestamp is not specified,the current time is used.


Format a date and time, adjusting the result to be Greenwich Mean Time(GMT):

$string = gmdate($format,$timestamp);

This function is equivalent to date(), the time is adjusted to be relative to GMT representation of the given time.


Get various information about a specified time:

$time_array = getdate($timestamp);

returns an array of various values based on the given time stamp. The keys to the are array seconds,minutes,hours,mday,wday,mon,year,yday,weekday
,month.


Get and set the time zone used by the time functions:

$string = date_default_timezone_get();
date_default_timezone_set($string);

This pair of funtions gets or sets the timezone identifier


Parse any English string representation of time and produce a time stamp:

$timestamp = strtotime($english_time);

This function can take nearly any string containing a textual description of a date and time, in English, and produce the corresponding time stamp.


Validate a date against the gregorian calendar:

$isvalid = checkdate($month,$day,$year);

Returns true if the specified date can be found on the Gregorian calendar. Useful to make sure that user input or calculated time is valid.


Find sunrise and sunset times for a given position:

$time_rise = date_sunrise($day_ts, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude);

$time_set = date_sunset($day_ts, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude);

This pair of funtions returns the time of sunrise and sunset at the specified location. The constant, SUNFUNCS_RE_TIMESTAMP, tell the function to return the time as a time stamp.



Convert a date between different calendars and Julian Day Count:

$jday_count = cal_to_jd($calendar,$month,$day,$year);
$date_array = cal_from_jd($jday_count, $calendar);


This pair functions converts a date, in a specified calendar system, to and from a Julian Day Count. These are useful for converting dates from one calendar to another. The supported calendar systems are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH.


I hope you interest about my post on my site. If u like any article,please subscribe now and bookmark for me. Thanks You. We will meet again. email me at Marx Nazrin

- G - Class Listing Download


DOWNLOAD CODE BY CLICK LINK BELOW


Geo Conversation - Convert coordinates between degrees and decimal download

GCurl - Perform HTTP requests using Curl download

Using GD Color Class - Manage colors allocated for GD images download

Gen Class - Generate MySQL table wrapper classes download

Gen Dummy Class - Generate class skeletons from existing classes download

Generic Array - Create arrays that allow members of just one type download

Geology IP - Determine the country of an IP address using GeoIP download

Gmap Builder - Present world maps on Web pages using Google Maps download

Google Hacks - Search the Internet for certain files using Google download

Google Translator - Translate texts between idioms using Google download

Grab Gmail - Grab the contact lists of a Gmail user download

Graph Colouring - Assign colors to graph points from a vertex list download

Gravatar - Retrieve Gravatar images download

Razon FTP Writer - Send files to an FTP server download

GPS Rinex - Parse GPS navigation messages in the RINEX format download


- F - Class Listing Download


DOWNLOAD CODE BY CLICK LINK BELOW


Feed Finder - Check whether an URL has an RSS or Atom feed Download

Ffmpeg - Manipulate and convert videos with ffmpeg program Download

Fast HTML Form Creator - Generate and validate Web forms Download

Fadpf - Generate PDF documents in the Farsi idiom Download

Find Date - Add to or substract day from date Download

Form Checker - Sanitize and validate user input data Download

FormLib4PHP - Generate and validate Web forms Download

Forum Integrator - Integrate with punBB and phpBB forum user systems Download

Fuse Box Manager - Generate Web applications using Fusebox framework Download


- E - Class Listing Download

DOWNLOAD CODE BY CLICK LINK BELOW


Easy Mail Smtp - Compose and send e-mail messages via SMTP download

Easy Mail - Compose and send HTML messages with attachments download

Easy Template - Template engine based on real HTML tag replacement download

Easy Thumbnail - Generate thumbnail images using the GD extension download

Edit File Tags - Find and replace tags in files with new values download

Email Parser - Parse e-mail messages using regular expressions download

Encode and optimize PHP - Obfuscate and compact PHP source files download

Error - Display exception call stack trace information download

Event - Register handlers and trigger event actions download

Extended Array Object - Create and manipulate arrays as objects download


- D - Class Listing Download


DOWNLOAD A CODE BY CLICK LINK BELOW

Daemon Emulation - Create and manage daemon processes download

Database Connection - Abstract the access to SQL databases download

Database Operation - MySQL database access wrapper download

Data Manipulate - Manipulating data using class download

Data To Graph - Generate bar charts from arrays of data download

Data To XML - Generate XML documents from data in MySQL database download

Date Difference - Calculate the difference between dates download

Date Buddy - Convert dates between ISO, MySQL and US formats download

Date Function - Spell the time relative to period or current time download

Day Iterator - Iterate the over the days of a range of dates download

Database Object - Object oriented database abstraction layer download

DB Connect Class - Simple MySQL database connection class download

Databse Code Assistant - Generate code to access databases as data objects download

DBrowser - Emulate a browser to extract content from sites download

Defensive Attack - Retrieve information of current user HTTP request download

Dev Color - Converts color values between RGB and hexadecimal download

Dictionary Object - Access arrays with the IDictionary interface download

Directory Match - Synchronize the files between two directories download

Distance Time - Calculate the speed, pace for distances ran download

Double Link List - Manage circular double-linked lists of objects download

Drastic Tools - Visualize MySQL data in Grid, Cloud and Map download

Dynamic Page - Replace comments in HTML templates with content download

Dynfetcher - Extract information from Web pages using SimpleXML download


- C - Class Listing Download


DOWNLOAD - CLICK LINK BELOW

Cache Zip Files - Cache zip content in files download

Cal Tag Cloud - Display a tag cloud from an array of tags download

Calendar Form - Display month calendars in Ukrainian download

Calendar Component - Generate calendar for a given month download

Chart Graphing Class - Generate line, bar and pie graphs and charts download

AMDev Captcha - Generate form elements for CAPTCHA validation download

Check Spam - Generate and validate CAPTCHA verification images download

Classfb - Wrapper to access Firebird databases download

Client Socket - Generic network client connection wrapper download

Class Image - Image manipulation with PHP 4 and PHP 5 support download

Class Mail Composite- Compose & send e-mail with attachments download

Code Map - Display the classes used by a PHP script download

coMySQL Class - MySQL database access wrapper download

Configuration Setting - Write and read configuration files like in .NET download

Connection PDO - Wrapper to access SQL databases using the PDO API download

Contact Grabber - Grab contacts of email and social networking sites download

Cookies Object Class - Store & retrieve composite data items in cookies download

Country From IP Adress - Lookup the country of a given IP address download

Cross Authentication - Authenticate users in multiple domains at once download

CSQLite - Wrapper to access SQLite databases under PHP 5 download

CSV managing class - Store and retrieve data from CSV files download

CSV parse and read - Parse and display data from a CSV file download

CSV tokenizer - Parse CSV files tokening data lines download

Currency Exchange - Convert values currencies using a XML feed download

Czechcourse - Get the conversion rates to the Czech currency download

- B - Class Listing Download


CLICK LINK BELOW TO DOWNLOAD


BarcodeGenerating -
Web interface to generate barcode images download

Bar Graphic - Generate bar charts using only HTML tables download

Binary Parser - Serialize and unserialize binary data download

Blogger Integration - Import a blog published in Blogger.com into a site download

BPT session manager - Manage user access sessions download

- A - Class Listing Download


PHP CODE TITLE FOR DOWNLOAD


Access Method -
Map variable accesses to accessor method calls download

Ajax Tree View - Update tree view on demand without page reloading download

All Date Class - Perform many operations with times and dates download

Array XML - Generate XML documents from associative arrays download

Autoload - Autoload classes from given directories download

AutoAjax - using ajax to create auto generate load download

ASession - Alternative management of user access sessions download

Ascii Crypt - Encrypt and decrypt text messages in pure PHP code download

Ascii Art - Render images using text characters download

Array Constant - Declare arrays as constants download

Acronym In PHP5 - Locate and process acronyms within text phrases download

Authenticator - Authenticate users with MS SQL SP_Login procedure download

Auction - For an auction code download

Cant Find?Try This.