PHP

Getting Started String Date If Else Loop Array Functions Session Files Super Global Variables Debugging MySQL MySQL Read Data JSON Markdown
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

PHP : Date

2017-01-01

Date

Date

date(format,timestamp);

// set timezone
date_default_timezone_set("America/Los_Angeles");

Todays Date

Returns todays date in a specific format.

date()   //error

date("Y-m-d")   // 2018-03-10
date("M d")  // Mar 10

date("Y")       // 2017 - year number

date("m")       // 09 - month number

date("d")       // 20 - day of the month number
date('w')    //6  - day of the week number

date("D")       // Wed - day short name
date("l")       // Wednesday - day long name

Time Right Now

//return time right now in milliseconds since 1970
time();  //1520712931

// return time right now in a specific format
date("h:i:sa")  // 09:29:48pm 
date("h:i:s")  // 09:29:48 
date("h:ia")  // 09:29pm 
date("h:i")  // 09:29 

strtotime()

Returns a timestamp (miliseconds since 1970) on success, or false otherwise. Accepts 1 string argument.

echo strtotime('2018-03-04');               //432198000
echo strtotime("now"), "
";
echo strtotime("10 September 2000"), "
";
echo strtotime("+1 day"), "
";
echo strtotime("+1 week"), "
";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "
";
echo strtotime("next Thursday"), "
";
echo strtotime("last Monday"), "
";

Get date format from another day

//return day of the week from specific day as day string
echo date("D",strtotime('1983-09-12')) ;  //Mon

//return day of the week of specific day as int
date('w', strtotime($record[1]))