Tags down


Find the Week from a date passed as input oracle

By : user52329
Date : September 17 2020, 09:00 AM
This might help you DB : Oracle Version : 12c , How about taking the difference in days and dividing by 7?
code :
select floor((sysdate - date '2019-11-03') / 7) + 1

Share : facebook icon twitter icon

Formula to find the week no. (which week out of 52 weeks in year that date lies) from the date

By : Kaan
Date : March 29 2020, 07:55 AM
hope this fix your issue With a date in A1,:
=WEEKNUM(A1) will give the week number.....For example if A1 contains:

Calculate the week ending date in oracle using Saturday as the week end date

By : John
Date : March 29 2020, 07:55 AM
it should still fix some issue Given any particular date / time value, this expression will return midnight of the preceding Sunday.
code :
 SELECT TRUNC(whatever_time,'DAY') week_starting,
        TRUNC(whatever_time,'DAY')  + 6 week_ending,
   FROM table
  GROUP BY TRUNC(whatever_time,'DAY')
SELECT TRUNC( DATE '2013-12-31', 'DAY'),
       TRUNC( DATE '2014-01-03', 'DAY')

Getting the date of a specific day of week when the week is passed in as a variable

By : Chase
Date : March 29 2020, 07:55 AM
may help you . I'm trying to figure out what a date(m-d-Y) would be for a specific week. The date that I'm trying to calculate would be passed in as the day string ('monday', 'tuesday', etc...) and the week would be a PHP DatePeriod object. I will be passing in a specific date and I would like to figure out any date of that DatePeriod week. Can anyone please help me?
code :
// Making test period
$begin = new DateTime( '2015-07-20' );
$end = new DateTime( '2015-07-27' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
// Array of day names    
$days = ['monday', 'tuesday', ... ];
// String we looking for
$string = 'tuesday';
// day of week - monday is zero  
$i = array_search($string, $days);

if ($i !== false) {
   // add i to find needed day
   echo $daterange->start->modify( "+$i day" )->format("Y-m-d");

How do i find number of weeks from start date to end of the current week in Oracle query?

By : user3023718
Date : March 29 2020, 07:55 AM
around this issue I always use something like following to count weeks as Change in the year of the start and end date can affect my result.
You can try the following:
code :
        DATE '2019-12-01' START_DATE,
        DATE '2020-02-26' END_DATE
--    , LEVEL   "Week",
--    TRUNC(START_DATE +(7 *(LEVEL - 1)), 'IW') + 6 AS END_OF_THE_WEEK,
    LEVEL <= ( TRUNC(END_DATE, 'IW') - TRUNC(START_DATE, 'IW') ) / 7 + 1;



Get start and end date of a week. Month, week number, and year is given as user input

By : user3415891
Date : March 29 2020, 07:55 AM
I hope this helps you . My code should bring the date of a particular week, when the user provide the month, week number, and year. For example: If my user input is month (String) --> "October", week (Int) -- > 1, year (int) --> 2019, the above input should give the response like startDate --> 01/10/2019, endDate --> 07/10/2019. , I came up with this that fulfills your criteria I think
code :
NSInteger year = 2019;
NSInteger month = 11;
NSInteger week = 1;

NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

cal.firstWeekday = 2;

NSDateComponents *comps = [NSDateComponents new];
comps.calendar = cal;
comps.year = year;
comps.month = month;
comps.weekday = cal.firstWeekday;
comps.weekdayOrdinal = week - 1;

NSDateComponents *startOfTheMonthComps = [NSDateComponents new];
startOfTheMonthComps.year = year;
startOfTheMonthComps.month = month;
NSDateComponents *endOfTheMonthComps = [NSDateComponents new];
endOfTheMonthComps.year = year;
endOfTheMonthComps.month = month + 1;

NSDate *startOfTheMonth = [cal dateFromComponents:startOfTheMonthComps];
NSDate *endOfTheMonth = [[cal dateFromComponents:endOfTheMonthComps] dateByAddingTimeInterval:-1];

NSDate *date = [comps date];
NSDate *startOfTheWeek;
NSDate *endOfWeek;
NSTimeInterval interval;
[cal rangeOfUnit:NSCalendarUnitWeekOfYear

endOfWeek = [startOfTheWeek dateByAddingTimeInterval:interval];

startOfTheWeek = [startOfTheWeek dateByAddingTimeInterval:-1];

if ([startOfTheWeek compare:startOfTheMonth] == NSOrderedAscending) {
    startOfTheWeek = startOfTheMonth;

if ([endOfTheMonth compare:endOfWeek] == NSOrderedAscending) {
    endOfWeek = endOfTheMonth;
NSLog(@"start %@", startOfTheWeek);
NSLog(@"end %@", endOfWeek);
Related Posts Related Posts :
  • Moving data between tables on a specific condition
  • Prime Number using GOTO statement in PL/SQL
  • How to get Check Out time for employee who is working on night shift
  • SQL Using Multiple Agregate Functions At Once
  • Msg 8152, Level 16, State 14, Line 1 String or binary data would be truncated
  • Insert automatically generated primary key into another table when inserting
  • Execute Package Utility (dtexecui) not installed after installing SQL Server 2017
  • Oracle Query: How to compare two column of different table having comma separated values
  • How do I update this query so as to use listagg instead of wm_concat?
  • Sampling for a SQL Database
  • Getting oldest record from SQL Server using T-SQL
  • How can Devise users create an invitation for others to accept and start and able to finish invitation
  • Create a group by and display a sequence number?
  • How to check if a "Send Query" is over?
  • Why is no data being returned
  • How to get records by using foreign key in one table using primery key another table in visual basic 6.0
  • what is the meaning of this code ..[select @a:=password(?)]
  • How avoid using group by SQL ORACLE
  • Wrong number or types of arguments error using cursors with parameters
  • Simple Subquery Statement, receiving an error
  • sql extract rightmost number in string and increment
  • How to convert column with Rank Value into rows in oracle
  • SQL Query to convert Particular Rows into Column
  • Why is PostgreSQL 11 optimizer refusing best plan which would use an index w/ included column?
  • SELECT Column Value based on Subselect if record exists
  • Autocast from "YYYY-MM" varchar to date in PostgreSQL
  • SQL - For each ID, values in other columns should be repeated
  • How to Replace multiple space in table column
  • How to convert unix timestamp to date with time zone?
  • How can I filter JSON column in Postgresql?
  • How to assign SQL query result to variable?
  • difficulties to fetching data from table
  • Merge Function limitation in snowflake
  • Display all the columns in employees table along with average salary of each dept
  • Can anyone help me to understand why oracle sql length function accepting numeric values or number datatype?
  • Snowflake - Check if 1st 3 Characters of string are letters
  • Most Elegant Way to Populate Nulls from Reference Table
  • Can anyone write this query without a cursor?
  • SQL - Incremental insert using SSIS?
  • Why is there such a big difference between performance of those two queries?
  • how would SQL Server interpret this where clause?
  • How to query with multiple conditions that won't match on just a single row
  • HANA SQL IsDate() equivalent or to_date function that takes invalid data?
  • How do I convert this query into one using joins/unions in SQL Server 2016?
  • Increment SQL Server variable across multiple SELECT queries
  • Delete rows where all columns (except ID) are NULL
  • What is wrong with my joining derived table query?
  • Converting a table to a different form
  • Only selecting certain rows based on calculated value
  • Extra quotes doing SQL insert from Perl to CSV. If I try to remove them, I get no quotes. I need single quotes as in &qu
  • Create table from table of column names and data types
  • SQL Loop through months
  • Making sure Identity column doesn't allow change in another value
  • Oracle SQL how to select (or include data) if it doesn't exist sometimes?
  • Select MAX between 2 similar ID
  • How to fix "is invalid in the select list because it is not contained in either an aggregate function or the GROUP
  • Is there a reason this procedure is not updating my Table?
  • Return Most Recent Record group by 2 ID fields
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk