Get closest Sunday and Saturday in current week with PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Given today's date, is there an elegant way to get the previous Sunday's and the next Saturday's date?
So, given today's date of 12/12/2013, I would want to get back 12/8/2013 for the Sunday and 12/14/2013 for the Saturday.
If given a Sunday, for example 12/15/2013, I would want to get back 12/15/2013 for the Sunday and 12/21/2013 for the Saturday.
If given a Saturday, for example 12/21/2013, I would want to get back 12/15/2013 for the Sunday and 12/21/2013 for the Saturday.
And so on.
Any ideas?

DateTime() accepts relative formats:
echo (new DateTime('last Saturday'))->format("Y-m-d");
echo (new DateTime('next Saturday'))->format("Y-m-d");
See it in action

Related

Showing a message if specific times on specific days [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to show a message on my site if it's after 5:00 PM on Thursday, and the whole day Friday.
I managed to get the code to work for Friday, but don't have any idea how to also get it to show on Thursday after 5.
Here's what I have so far:
$d=date("D");
if ($d=="Fri")
{
echo 'Items may ship out after the weekend.';
}
How can I also get this to show on Thursday after 5:00?
Thanks!
You can try this:
$d=date("D");
if ($d=="Fri" || ($d=="Thu" && date("Hi")>="1700")) {
echo 'Items may ship out after the weekend.';
}

Calculate time stamp from date and time given by user [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my application, the user gives 2 inputs — one is date and the other is time:
$date = date("d-M-Y");
$time=date("h:m:s");
How can I calculate a time stamp from these two variables in PHP?
actually i take the date form date picker and time from time oicker.....
If you want time stamp then use this
echo strtotime($date.' '.$time);

How to get date in Thursday, September 26, 2013 format? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to get date in following format Thursday, September 26, 2013.
The name of day should be full like Monday not like Mon and same for the month format.
How to get this format?
Use php date function as below.
echo date('l,F d,Y',strtotime($date));
Date Format
I got this like following way
$mydate=getdate(date("U"));
echo "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]";
OR
$today = date(DATE_RFC822);
echo date('l,F d,Y',strtotime($today));

strtotime() and easter_date() won't work together [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm trying to get the day after the easter date:
date("d-m-y", strtotime(easter_date(), '+1 day'));
I don't understand, the date showed is still the same, but when I try this:
date("d-m-y", strtotime('+1 day'));
It works.
How can I do?
That's because easter_date() produces a unix timestamp:
1364713200
And strtotime() is meant for this like 'today' and 'tuesday next week';
If you just want to add a day to it, just add 86400 (this is how many seconds are in a day) to easter_date();
So: date("d-m-y", easter_date() + 86400);
The function easter_date() returns a UNIX timestamp (e.g. 123338898) whereas strtotime()'s first parameter must be a valid date/time string (e.g. 2013-05-30 23:59:59). Valid formats are explained in Date and Time Formats.
Additionally, from the PHP documentation for strtotime():
Using this function for mathematical operations is not advisable. It
is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and
later, or DateTime::modify() in PHP 5.2.

how to increment the current date which is in d/m/Y format by one month [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to increment the current date by one month which is in d/m/Y format
but i have no idea about this,can any one give me a relevant example.
thanks in advance
In PHP you do this:
$time = strtotime("+1 month", time());
$date = date("d/m/Y", $time);

Categories