Hi all,
I am having a problem with calculating a date. What I am looking to do
is get the date of Sunday of this week, then use mktime() to find out
other days in the past by subtracting days.
In the code below, today is Saturday, October 16, 2004, this week's
Sunday is 2004-10-17. I successfully get that.
But, when I try to subtract 7 days using mktime(), I instead of getting
2004-10-10, I get 1969-12-31.
I have looked through php.net/mktime and searched some example via
Google, but I stuck. Any help would be greatly appreciated.
CODE BELOW:
$today = unixtojd();
// GET THIS WEEK'S SUNDAY
$this_sunday = $today + (7 - jddayofweek($to day)) % 7;
$current_sunday = jdtogregorian($ this_sunday);
$this_sundays_p arts = explode("/",$current_sund ay);
$cur_sunday = $this_sundays_p arts[2] . "-" . $this_sundays_p arts[0] .
"-" . $this_sundays_p arts[1];
// GET LAST WEEK'S SUNDAY
$last_sunday = date("Y-m-d", mktime(0, 0, 0,
date($this_sund ays_parts[2]), date($this_sund ays_parts[0]),
date($this_sund ays_parts[1])-7));
// PRINT OUT THE DATES
print "This Sunday is " . $cur_sunday . "<BR>";
print "Last Sunday was " . $last_sunday . "<BR>";
Thanks for any help!
- Adam 1 2746
adam wrote: But, when I try to subtract 7 days using mktime(), I instead of getting 2004-10-10, I get 1969-12-31.
I have looked through php.net/mktime and searched some example via Google, but I stuck. Any help would be greatly appreciated.
Try the following:
$this_sunday_ts = mktime(0, 0, 0,
$this_sundays_p arts[0],
$this_sundays_p arts[1],
$this_sundays_p arts[2]
);
$last_sunday_ts = $this_sunday_ts - (86400 * 7);
$last_sunday = date("Y-m-d", $last_sunday_ts );
HTH;
JW This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeroen |
last post by:
Hi,
I'm searching but not finding :(
I need the code that creates automatic the days in a month
So like for this month, it creates the days in this format 01-Oct, 02-Oct,
....
This should be used in a form so when opening the page, automatic all the
|
by: Yannick Turgeon |
last post by:
Hello all,
One of our PHP program bugged recently. I've reduced the problem to this:
April 4th!
Anybody can tell me if I'm doing something wrong? Why April 4th is not
printing but replaced by April 3rd? I'm using PHP 4.3.5
Yannick
|
by: gsv2com |
last post by:
Maybe I'm tired, but I'm having a small problem with a date function I'm
writing. Total noobish I know, but this is just going beyond me for some
reason...
What I want to happen is send a date (such as June 31, an invalid date) and
have the function turn it into a real date by subtraction. In other words,
the function would turn the date to June 30, run itself again, and if June
30 is a real date, it'd return it back to the program.
...
|
by: Matt |
last post by:
Given a date, how to find the beginning date and ending date of that week
please advise!
|
by: newtophp2000 |
last post by:
I need to add the ability for the users to select a date on one of our
web pages. The examples I was given by some users were in JavaScript.
Is there a free date picker that I can use? I saw one at
http://webfx.eae.net but it does not seem to be free.
Thanks!
| |
by: laredotornado |
last post by:
Hi,
Using PHP 4.4.4 and I'm getting an odd time stamp attempting to make a
php date. Here's the code
$reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
$reqDateTS = strtotime($reqDate);
If $y = 2006, $m = 12, and $d = 28, I get a negative value for
$reqDateTS. What is wrong with the above statement?
|
by: JJ |
last post by:
Here's the code.
$link="http://xbox360cheat.org";
$close_date=$_POST; #last content change check
if ($close_date == 0)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+7, date("Y")));
else if ($close_date == 1)
|
by: osward |
last post by:
Hi everyone,
Background
1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >= current date. Otherwise, user have to waste time to page up the pages to find the current date
2. I got a script of simple calendar from the web that use mktime() to create links on the calendar
Task
I need to let user view data earlier than...
|
by: ashore |
last post by:
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>
AS
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |