Solved

using sysdate in an Oracle query

Posted on 2014-03-27
3
772 Views
Last Modified: 2014-03-27
Experts,

Does anyone know the syntax in Oracle to find a date?

Examples:
the first day of the current month
The first day of the current week
0
Comment
Question by:morinia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 125 total points
ID: 39960061
select trunc(sysdate,'mm') from dual -- first day of month


select trunc(sysdate,'dy') from dual -- first day of week


week start/end is dependent on NLS calendar settings
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 125 total points
ID: 39960074
SELECT TRUNC(SYSDATE, 'MM') First_Day_Of_Month,
         TRUNC(TO_DATE(SYSDATE),'D') First_Day_Of_Week
 FROM dual;
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39960106
TO_DATE(SYSDATE)

don't do TO_DATE() on SYSDATE, it's already a date

  just put the TRUNC directly against the sysdate result as shown in the first post
0

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question