Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:33:15+00:00 2026-06-17T22:33:15+00:00

I currently need to get the previous week from a variable that passes a

  • 0

I currently need to get the previous week from a variable that passes a php week number so if it is week 13 I will get week 12.

The problem I am facing is that if I just minus 1 from the original number if I am in week 1 it will return week 0 unless I create an if statement ie:

if($week==1)
{
    $prev_week=52;
    $prev_year=$year-1;
}

This is assuming that php counts the weeks from 1 and not 0. This seems a bit clumsy and I was thinking there may be a better way of doing this utilizing PHP’s many date and time functions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:33:16+00:00Added an answer on June 17, 2026 at 10:33 pm

    I think I could be over complicating the problem – basically I need to obtain results from the database that appear in the previous weeks from the selected week therefore if there is a possibility of 54 weeks in a year all I really need to do is:-

     if($week==1)
     {
        $year_minsued=$year-1;
        $week_minused=54;
     }
     else
     {
        $week_minused=$week-1;
        $year_minused=$year;
     }
    

    My select statement can then read:

    SELECT SUM(post_price), SUM(total_price) FROM
    database_table
    WHERE client_id='$account_no'
    AND
       (year<='$year_minused' AND week<='$week_minused')
    

    I have not tested this as yet but thinks it should do the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get select the closest previous date to a date parameter. Currently
I have an exchange rate table. I need to get current rate and previous
I'm currently in a need of getting session ID thus I need to get
Currently I need to run two queries to get both the total amount of
I need to get the content of URL bar (of currently opened tab) of
I am currently working with a file name and I need to get the
All I need is to get the list of currently open documents in the
How to get the previous URL in Rails? Not the URL that you got
Currently, to get the data I need, I need to execute multiple SQL statements:
I am currently in need of 8 TabBarItems , and I can show just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.