473,508 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date get previous day

15 New Member
Hi,
I need to get previous day from an existing date stored in a varaible $date which will not include any weekend (saturday and sunday)
if it is on monday date should be for friday

How can I do this??

Thanks,
Jas
Nov 29 '07 #1
1 3038
nathj
938 Recognized Expert Contributor
Hi,
I need to get previous day from an existing date stored in a varaible $date which will not include any weekend (saturday and sunday)
if it is on monday date should be for friday

How can I do this??

Thanks,
Jas
Hi Jas,

This is how I would do it. I think you can probably replace the switch with a loop to make it more elegant but this will work as it is:

[php]
<?php
$lcYesterday = mktime(0, 0, 0, date("m") , date("d")-1, date("Y"));
switch (date('N',$lcYesterday))
{
case "6": // yesterday was Saturday, today is Sunday so it's 2 days back to Friday
$lcLastWorkingDay = mktime(0, 0, 0, date("m") , date("d")-2, date("Y"));
break ;
case "7": // yesterday was Sunday, today is Monday so it's 3 days back to Friday
$lcLastWorkingDay = mktime(0, 0, 0, date("m") , date("d")-3, date("Y"));
break;
default:
$lcLastWorkingDay = $lcYesterday ;
}

echo date('l' , $lcLastWorkingDay) ;
?>
[/php]

I hope this helps
nathj
Jan 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2560
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
3
7449
by: gregmalenky | last post by:
Visual C# 2005 Express - I am creating a employee scheduling program for work. When I need to do is for the program to open with a start date of the previous sunday. I also want the ability to...
7
1452
by: Drygast | last post by:
I have a form where I would like to get the todays date and when the date is 15 or less I would like to assign a textfield the last date of previous month and when the date is larger then 15 I...
1
2742
by: Riaan | last post by:
Hi There, I am a newby with SQL and I am trying to run a query on a date/time field. The query is for the previous date. I would like to create this as a criteria in a view, but not sure what the...
2
1484
by: Amanda | last post by:
This is hotel reservation when a departure date is changed manually by user input ( to a valid date in date format - validity is checkedsomewhere else), the arrival date is set to the previous date...
6
5154
by: sangith | last post by:
Hi, Is there any module which checks for the previous day's date. For eg I run the program which gives me the current date and I have to check another log file to see if it contains the timestamp...
2
2333
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous...
7
5322
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
1
2791
by: Del | last post by:
I have a parameter query that requires the user to enter a Start Date: and End Date: and pull data between that date range. I am currently using the following parameter; Select * From mytable...
2
4151
by: DThreadgill | last post by:
Not sure how to begin with this one. My table consists of: Branch# (number, double) EntryDate (datetime, mm/dd/yyyy hh:mm:ss am/pm) One branch can have many entry dates (i.e, Branch # 76...
0
7224
marktang
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,...
0
7120
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...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7494
tracyyun
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...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.