473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Date manipulation PLEASE

Des
I have to do an events calender for a church. The events display will
be limited to that week. If someone went in today Wed 24th I want to
display 21st to 27th. I dont want any code samples, just the functions
that find the day of week and a function that can (in this case)
subtract 3 days to get sunday and add 7 for saterday. I can do the
rest.

Desmond.

May 24 '06 #1
5 2083
"Des" <de*********@aol.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
I have to do an events calender for a church. The events display will
be limited to that week. If someone went in today Wed 24th I want to
display 21st to 27th. I dont want any code samples, just the functions
that find the day of week and a function that can (in this case)
subtract 3 days to get sunday and add 7 for saterday. I can do the
rest.


I'd try something like this:

$lastsunday = date('w')==0 ? mktime() : strtotime('last sunday');
// If today _is_ sunday, then today, else last sunday
echo date('Y-m-d',$lastsunday);

$nextsaturday = strtotime('next saturday',$dateforlastsunday);
// Next saturday counting from the given sunday.
echo date('Y-m-d',$lastsaturday);

strtotime is a pretty darn good way for getting expressional dates like
"next month" or "last year" etc.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
May 24 '06 #2
Des
Well this kind of works. The code output i get is

2006-05-21
1970-01-01

I don't think 1970 is the next saturday. Also I need this in a format
suitable for an SQL Query.

Des.

May 24 '06 #3
"Des" <de*********@aol.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com...
Well this kind of works. The code output i get is

2006-05-21
1970-01-01

I don't think 1970 is the next saturday. Also I need this in a format
suitable for an SQL Query.

Des.


Sorry about that, and way to go with sarcasm by the way. (It always helps
when someone is trying to _help_ you and you reply sarcastically "I don't
think 1970 is next saturday"...) I first wrote the code using variable names
$dateforlastsunday but then changed them to $lastsunday etc... Except in one
critical place... :) Below is a working code with the typo fixed.

$lastsunday = date('w')==0 ? mktime() : strtotime('last sunday');
// If today _is_ sunday, then today, else last sunday
echo date('Y-m-d',$lastsunday);

$nextsaturday = strtotime('next saturday',$lastsunday);
// Next saturday counting from the given sunday.
echo date('Y-m-d',$lastsaturday);

YYYY-mm-dd is a general date format that most databases do support and since
you mentiond you can do the rest, I'm sure you'll be able to make with the
correct date format on your own.

Just in case: http://php.net/manual/en/function.date.php

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
May 24 '06 #4
Des
Problem solved re-invent the wheel. add to functions to the include
file

function Sunday()
{
$day = 86400;
$stamp = time();
$sunday = date('w',$stamp);
$stamp -= $day * $sunday;
echo date('Y-m-d',$stamp);
}

function Saturday()
{
$day = 86400;
$stamp = time();
$sunday = date('w',$stamp);
$sunday = 6 - $sunday;
$stamp += $day * $sunday;
echo date('Y-m-d',$stamp);
}

May 24 '06 #5
Rik
Des wrote:
I have to do an events calender for a church. The events display will
be limited to that week. If someone went in today Wed 24th I want to
display 21st to 27th. I dont want any code samples, just the functions
that find the day of week and a function that can (in this case)
subtract 3 days to get sunday and add 7 for saterday. I can do the
rest.

You don't want codesamples?
Ok, return your day of the week with date() or strftime(), make dates with
mktime().

Grtz,
--
Rik Wasmus
May 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
5
by: John Kiernan | last post by:
Hey JavaScript gurus! Here's a weird one: If I check (with an alert) this line: vStrDate2 = vDate.toLocaleString(); I get: Saturday, August 14, 2004 7:57:30 PM (as I should) but this...
26
by: sgershon | last post by:
Hi. I know this is should be a simple question. I know server-side web-programming, and never needed to use client-side scripting... until now :) I have done so far a little number of scripts...
3
by: andrew | last post by:
Hi: I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member Key) . Thus I am sorting the records by...
5
by: WindAndWaves | last post by:
Hi Gurus This is a cry for help to all of you. I am looking for some sort of plug-in/active X/code/link to outlook/what have you, which I can add to my MS Access database for my users to...
1
by: Graham Feeley | last post by:
I have a date field named rcdate it is a general date eg: 12/08/2006 3:30:00 PM 12/08/2006 3:00:00 PM I used to update another empty field named rdate with the with using in a update query "...
2
by: Billy | last post by:
This string is supposed to provide all records from an MDB database that match the courier and date specified in the query. I Response.Write the query and I get a date as 1/27/2007. The date...
3
by: Bharathi | last post by:
Hi, I got strucked with reading date value from excel file using C#.NET. For Jan-2000 the value I am getting is 36526.0. For all other dates also I am getting some double value like this. ...
3
by: GorseFox | last post by:
Forgive me. I am new to PHP and am a little confused by date manipulation and would appreciate some guidance. I have a string containing a date which has been parsed from and RSS feed. This looks...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.