473,385 Members | 1,312 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,385 software developers and data experts.

current date - 7 dayz?

hi,
i am wanting to get the date 7 days ago but wasnt sure how to do it.
something like:

$current_date = date("Y-m-d") - [seven days];

also, i would like to expand this to get the date 3/6 months ago or a
year ago. any ideas? cheers

burnsy
Jul 17 '05 #1
3 5237

On 7-Oct-2003, bi******@yahoo.co.uk (mr_burns) wrote:
i am wanting to get the date 7 days ago but wasnt sure how to do it.
something like:

$current_date = date("Y-m-d") - [seven days];

also, i would like to expand this to get the date 3/6 months ago or a
year ago. any ideas? cheers


$when = '2003-04-01';
$dayminus7 = date('Y-m-d',strtotime("$when -7 day"));
$dayminus3months = date('Y-m-d',strtotime("$when -3 month"));
$dayminus1year = date('Y-m-d',strtotime("$when -1 year"));

You can also use $when = 'now'; for the current date.
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
"mr_burns" <bi******@yahoo.co.uk> wrote in message
news:65**************************@posting.google.c om...
hi,
i am wanting to get the date 7 days ago but wasnt sure how to do it.
something like:

$current_date = date("Y-m-d") - [seven days];

also, i would like to expand this to get the date 3/6 months ago or a
year ago. any ideas? cheers

burnsy


$date = date ("Y-m-d", time () - (7*86400)); //Last week's time

Just change the 7 to 91 and 182 for the other two time periods. If you're
after an accurate 3/6 month period, you'd have to convert today's month into
a number, subtract 3 from it (or 6). If this month is then less than 1, add
12 to it and subtract 1 from the year. Stuff all this back in and you'll get
your date.

Paulus
Jul 17 '05 #3
On 7 Oct 2003 16:56:51 -0700, bi******@yahoo.co.uk (mr_burns) wrote:
hi,
i am wanting to get the date 7 days ago but wasnt sure how to do it.
something like:

$current_date = date("Y-m-d") - [seven days];

also, i would like to expand this to get the date 3/6 months ago or a
year ago. any ideas? cheers


http://www.php.net/manual/nl/function.date.php

<?php
// 7 days ago
$date7daysago = date("Y-m-d", mktime (0, 0, 0, date("m"),
date("d") - 7, date("Y")));

// 3 months ago
$date3monthsago = date("Y-m-d", mktime (0, 0, 0, date("m") - 3,
date("d"), date("Y")));

// etcetera...

?>

--
Greetz,
De Snor
Jul 17 '05 #4

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

Similar topics

14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
6
by: vijayk | last post by:
Hi all, I have a field which has data as YYYYMMDD, and I have to find the age of the person by substracting it from current date. can you please please advice... thanks
0
by: Shawger Lager | last post by:
Hi, I am new to DB2 (and SQL) and I am having some problems with the current date. I am trying to make sure the date in the table review is not past the current day using a constriant. I have tried...
3
by: seanw89 | last post by:
I have a bit trouble in converting CURRENT DATE into a integer type as YYYYMMDD. The following script is trying to find a day matching a date column with integer type with yesterday (CURRENT DATE...
0
by: remya1000 | last post by:
I need to display current month,last 3months,6months and 1year records seperatly. and first i'm tring to display current month's records. and the error i received is this. Microsoft VBScript...
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
2
by: NitinSawant | last post by:
Hello Experts, I'm newbie to php, I want to get date 30 day back from current date using php. i'm able to get current date, $currentDate= date("d-M-y",time());
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.