PHP calculates how many days are left until your birthday

Updated on society 2024-04-11
9 answers
  1. Anonymous users2024-02-07

    declare @t table(id int identity(1,1), date of birth datetime).

    insert into @t

    select '1985-09-3'

    union all select '1977-09-04'

    union all select '1978-11-25'

    union all select '1979-11-26'

    union all select '1987-11-27'

    union all select '1999-11-28'

    union all select '1999-11-29'

    union all select '1999-11-30'

    select * from(

    select *, number of days = datediff(day, getdate(), dateadd(year, year(getdate()) year(date of birth), date of birth)).

    from @t) a

    ID Date of Birth Number of days.

    8 rows affected).

  2. Anonymous users2024-02-06

    Get the timestamp of the birthday first, then subtract time().

  3. Anonymous users2024-02-05

    Countdown to birthday.

    birthday = "2017-12-29";

    date_default_timezone_set("prc");

    Today's timestamp.

    today = time();

    echo "Today is".date("y-m-d",$today)."

    Birthday timestamp.

    bstamp = strtotime($birthday);

    How many days countdown.

    rev = ceil(($bstamp-$today)/(24*3600));

    echo "It's your birthday just yet".$rev."days";

  4. Anonymous users2024-02-04

    The idea is to find the difference between the seconds of the two times, and then convert the result

    echo calctime('2018-08-20', '2018-08-30');

    function calctime($fromtime, $totime)

  5. Anonymous users2024-02-03

    This can only give you an idea.

    PHP has a function that directly outputs the timestamp strtotime( of a certain day'2018-08-30');。

    Use this timestamp to subtract the current timestamp, and then use the result of subtraction 3600 24 to calculate the number of days Generally, it is necessary to take the downward movement (less than 1 day is counted as 0 days).

  6. Anonymous users2024-02-02

    Wouldn't it be nice to add up the number of days in each month, let's talk about the specific needs, like getting the number of days in March 2018 is as follows:

    Get the number of days in March 2018.

    day = date('d', strtotime('2018-03'));

  7. Anonymous users2024-02-01

    : The calculation methods are not limited to those described below, but some of the more conventional methods:

    The php time and date function strtotime above has turned the string date into a timestamp, so that you just subtract the two values, and then turn the seconds into days, the comparison is simple, as follows:

    days=round(($enddate-$startdate)/3600/24) ;

    Here's another way to do it:

    The above is the size of the two dates, and the following is the program for judging birthdays**, and the $n obtained is the number of days apart from the birthday.

    birthday=birthday;

    birthday = preg_replace(‘/d+/’, date(‘y’),birthday, 1);

    d = 60*60*24;

    n= floor((strtotime($birthday)-time())/$d);$n=$n+1;

    Also, if you compare it to the current time, you can use the time() function to get the current timestamp.

    In the second case, there is a database, which is relatively easy! If it's mssql, you can use triggers! Use the function datediff() that calculates the date difference!

    If it's MySQL, then use the timestamp values of the two date fields and calculate the difference in days to get the difference. The method is very similar to the ** above.

  8. Anonymous users2024-01-31

    $date1 = strtotime('2016-12-10');Convert dates to timestamps.

    date2 = time();Take the timestamp of the current time.

    nowtime=strftime("%yy-%m-%d-day",$date2);Format the output date.

    days=round(($date1-$date2)/3600/24);Round.

    echo "Today is".$nowtime."";

    echo "

    distance".strftime("%yy-%m-%d-day",$date1)."And there is".$days."days";

    Hope it can be adopted, thank you.

  9. Anonymous users2024-01-30

    Convert two dates to timestamps: the larger one is subtracted from the smaller one and divided by the number of seconds in a day to get the date distance.

    strtotime date conversion timestamp.

    Write the program yourself, it's clear.

Related questions
13 answers2024-04-11

Divide into n groups, then divide by n!

For example, if you divide 3 books into 3 groups, it is clear that there is only one way to divide them. >>>More

6 answers2024-04-11

The national computer grade exam is basically useless, if you have the time and energy, and money, you should take the test, Huawei or Cisco.

16 answers2024-04-11

The main learning content of high school computer class:

1. Basic knowledge of computers: the development and application of computers, the number systems commonly used in computers, the composition of computers, and microcomputer systems. >>>More

7 answers2024-04-11

2. Search for free junior high school education resources on the Internet**, here we recommend the learning pocket network. **It has a wealth of junior high school teaching resources such as test questions, courseware, and lesson plans, and all resources are free**. >>>More

7 answers2024-04-11

The general meaning is this: because there is love, there is concern, so there is worry and panic. When there is no love in the heart, there will be no worries and no worries.