Click here to Skip to main content
15,991,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
sqlcmd.CommandText = "SELECT DATENAME(dw,'" +txtdate.Text+ "') as theDayName ";
string result = ((string)cmd.ExecuteScalar());
cmd.Parameters.Add("@dayname", SqlDbType.VarChar).Value = result;
Posted
Comments
PIEBALDconsult 25-Jun-15 1:16am    
It should be in result, no? But why use the database rather than System.DateTime ?
https://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v=vs.110).aspx
Abhipal Singh 25-Jun-15 1:19am    
Well, I am trying to understand the intent here. Weekday can be found by c# code, is there any specific reason to use SQL?
Also, the parameter @dayname is added after the query is executed! and the param is not even used in the sql command. Something is fishy here..

Can you please explain what you are trying to do?
Member 10978775 25-Jun-15 1:21am    
Hi,i got an err at string result..
i want the dayname in string result
then my stored procedure can accept the day and checks whether it is there r not?
can anyone help me out regarding this?

1 solution

This Query Execute in your SQL Server After Execution It Returns Current Day of Week.

SQL
select datename(dw,getdate()) --> e.g Thursday

select datepart(dw,getdate()) --> e.g 5
 
Share this answer
 
Comments
Member 10978775 25-Jun-15 1:29am    
i don't want the system date... the date which is selected by user that is stored in texbox. after selecting the date then i have button to display the available timings of doctor(doctor already inserts his working hours). so first i want to check whick date user has to book the appointment? in my database i need to check day of week first because working hours may different in a week
Abhipal Singh 25-Jun-15 1:39am    
Do you have a table where you store available timings of doctor?
If yes, are you checking the textbox date with the days in that table?
Anil Vaghasiya 25-Jun-15 2:02am    
Hello,
You have to Create StoredProcedure and Pass the Date which is selected by user at Page Site
CREATE PROCEDURE [dbo].[GetDayOfWeek]
(
@Dt Datetime
)
AS
BEGIN
SELECT DATENAME(dw,@dt)
END

At Page Site You have to Create Function and Pass the Parameter
sqlCom = awrDataObjectFactory.CreateStoredProcedureCommand("GetDayOfWeek", sqlCon);
sqlCom.Parameters.Add(awrDataObjectFactory.CreateInputCommandParameter("@dt", txtdate.Text));
sqlRed = sqlCom.ExecuteReader();



For Example :- Execute this Query in Your SQL Server
DECLARE @dt Datetime ='06/25/2015'

BEGIN
SELECT DATENAME(dw,@dt)
END
[no name] 25-Jun-15 5:58am    
Thanks its Working fine in My case.
Anil Vaghasiya 17-Jul-15 5:08am    
you are most welcome please mark answer as solution..!
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900