473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

query regarding date format

select last_name,hire_date,to_char(hire_date,'DAY') DAY
from employees
order by to_char(hire_date-1,'d')

i wanted to know how the function to_char(hire_date-1,'d') works...
its basically a query used to find the day on which a employee was
hired ,also it requires that the query be sorted by the day of the
week on which the employee was hired.

it'll be helpful is someone replies to this
Jul 20 '05 #1
2 2839

"amiya" <am******@rediffmail.com> wrote in message
news:cc**************************@posting.google.c om...
select last_name,hire_date,to_char(hire_date,'DAY') DAY
from employees
order by to_char(hire_date-1,'d')

i wanted to know how the function to_char(hire_date-1,'d') works...
its basically a query used to find the day on which a employee was
hired ,also it requires that the query be sorted by the day of the
week on which the employee was hired.

it'll be helpful is someone replies to this


to_char() is not a SQL Server function (I think it's Oracle, but I'm not
sure). Depending on what the query above is doing, this might be an MSSQL
equivalent, but I don't know what to_char() does, so I may be wrong:

select last_name, hire_date, datepart(dd, hire_date) as 'day'
from employees
order by datename(dd, hire_date)

Simon
Jul 20 '05 #2
am******@rediffmail.com (amiya) wrote in message news:<cc**************************@posting.google. com>...
select last_name,hire_date,to_char(hire_date,'DAY') DAY
from employees
order by to_char(hire_date-1,'d')

i wanted to know how the function to_char(hire_date-1,'d') works...
its basically a query used to find the day on which a employee was
hired ,also it requires that the query be sorted by the day of the
week on which the employee was hired.

it'll be helpful is someone replies to this


Try

select last_name,hire_date, datename(dw,hire_date) as DAY
from employees
order by datepart(dw,(hire_date-1))
datename with dw parameter will give Monday, Tuesday etc.

datepart with the dw parameter will give 1,2,3 etc where Sunday is 1
and Saturday is 7
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Albert Ahtenberg | last post by:
Hi, I have a database with a date field. And I would like to see the report grouped by a ceratin month and year, how can I do that without multiple queries? Albert Ahtenberg
7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
2
by: Dalan | last post by:
Having searched the archives regarding a Delete Query, I found nothing specific to my need, although there seems to be a plethora of ideas and suggestions on queries in general. I have used Delete...
2
by: Andy | last post by:
Hello, I have a question regarding how to format a date in VB so that I can call it from a query and get results. I'm calling functions in the query because that was the only way I found I could...
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
0
by: astersathya | last post by:
Date Format in MS Access using a query Hi I want to alter the existing column's format using the alter query. The issue I am facing is I want to set the default date format of an existing...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
3
by: jamieharrop | last post by:
Afternoon all, I've been battling with this all day today and my brain is now pretty much fried. I have one table that lists several details about my customers (name, address, phone, date of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.