Php obtains the day of the week, the day of the week, and the day of the next week.

Source: Internet
Author: User

Php obtains the day of the week, the day of the week, and the day of the next week.

<? Php

$ Today = date ("Y-m-d ");

Echo $ today; // you can get the number of today. Output

// Define an array first.

$ Rows = array ("day", "one", "two", "three", "four", "five", "Six ");
Echo "Today is the week". $ rows [date ("w")]. "<br> ";

// Note date ("w"). You can obtain the number of weeks, for example, 123. Note that 0 is Sunday. The subscript of the array starts from 0.

// Quickly obtain the corresponding date of the week

Echo "Monday is ". date ('Y-m-d', strtotime ("this Monday ")). "<br>"; // output. Because today is just Monday, the result is special. If you are interested, open it tomorrow to see if the result is correct.

// Quickly obtain the date corresponding to the next Monday

Echo "this Monday is". date ('Y-m-d', strtotime ("next Monday"). "<br>"; // output 2014-10-6

?>

PS: The strtotime () function parses the datetime description of any English text into a Unix timestamp.

Attached weekly English: Monday ['m then ndi,'m then ndei]

Tuesday ['tju: zdi]
Wednesday on Wednesday ['wenzdei, 'wenzdi]

Thursday on Thursday ['θ hour: zdi]

Friday ['fraidi]
Saturday ['s week t week di]

Sunday ['s Sunday ndi]


In PHP, how does one calculate the day of the week on January 1, July 8, 2013? Is the day of the year?

$ Strtime = "2013-7-8"; // required time
$ Time = strtotime ($ strtime );
Echo $ strtime. "Week:". date ('w', $ time). "<br> ";
Echo $ strtime. "is the number in the year:". date ('Z', $ time). "day <br> ";

Php allows the customer to give a date, and then outputs the day of the week Based on the date. You can give it a better idea.

Date ("w", "y-m-d") Function Format is Y, M, month, d, is the day of the week (note that the result is 0-6 Sunday corresponding to 0)
I wrote a code below. Based on the input year, month, and day, I got the day of the week. I didn't add any input judgment or drop-down menu. That's just a thought.
// Form
<Form method = post action = ''>
<Input type = text name = year size = 4> year
<Input type = text name = month size = 2> month
<Input type = text name = day size = 4> day
<Input type = submit name = "sub" value = "submit">
</Form>
<?
If (isset ($ _ POST ["sub"])
{
$ Date = $ _ POST ["year"]. "-". $ _ POST ["month"]. "-". $ _ POST ["day"]; // The input value is in Y-M-D format $ date
Echo $ date;
$ Weekarray = array ("day", "one", "two", "three", "four", "five", "Six "); // an array is used to convert the obtained numbers into Chinese characters.
Echo "is a week". $ weekarray [date ("w", strtotime (". $ date.") // output
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.