473,662 Members | 2,760 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 3047
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',$lcYe sterday))
{
case "6": // yesterday was Saturday, today is Sunday so it's 2 days back to Friday
$lcLastWorkingD ay = 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
$lcLastWorkingD ay = mktime(0, 0, 0, date("m") , date("d")-3, date("Y"));
break;
default:
$lcLastWorkingD ay = $lcYesterday ;
}

echo date('l' , $lcLastWorkingD ay) ;
?>
[/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
2565
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, IT.itemid, IT.date,
3
7452
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 change the start date to create a new schedule - however, it must begin on a sunday. I want the sunday date to be locked in so it doesn't always show the current date when executed. Also for a prompt to appear if the user tries to use another day...
7
1460
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 need to set the textfield to the 15:th of present month.... The code is wrong I know, but to clearify a little how I'm thinking: If Date.Now <= 15 Then
1
2752
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 criteria should look like doing a previous day query. The test query I have done using SQL analyzer is (select * from mvs_store_all_data_time_change where mvs_creation_date like '060801%'). This returns the previous days data, but is hard...
2
1495
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 upon MouseLeave. How do I calculate the date of the previous day (see mdatArrivalDate = ???? )? (I have already done calculating departure date when an arrrivalDate is modified manually - not via selecting on calendar - to valid data by...
6
5177
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 as the previous day's date. If it is present, I have to print that particular line to the screen. So please let me know if there is a module available to check for the previous day date. Thanks, Sangith
2
2345
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 days work I format the date to 7/19/2007 using a query Format(,"mm/dd/yy") so that they see everything for that date and not just that time. My questions is that when work is stamped after 12 midnight it date stamps to the next day, How do I...
7
5331
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 date System.out.println(string_dob); s.Info_DOB=Date.valueOf(string_dob); runs perfectly fine in the method insert() and throws up an illegal Exception in the method UPDATE.This is the error I get when I pass a date "1979-05-02"
1
2801
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 Where between and This query will always be run on a Monday and the start date will always be the previous Sunday. The end date will be the previous
2
4163
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 has 10 entry dates). I'm trying to show the most recent entry date & the previous entry date on a report. I know how to get the most recent entry date using Max. How would I get to the previous entry date? (Current is 2/14/2008 2:26:07 PM and...
0
8435
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, 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...
0
8345
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,...
0
8857
Oralloy
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...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7368
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 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...
0
4181
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...
1
2763
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 we have to send another system

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.