Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am doing image slide show these images slide with images in sqlserver related to sys date and i have entered current date column values as august5 but my sys date is 05-08-2015 so for tomorrow my images should slide with august 6 but my sys date 06-08-2015
so any body giveme idea or give me any examples
Posted
Comments
Maciej Los 5-Aug-15 9:13am    
Wrong approach. You have to re-think database design. I would suggest to add corresponding date field.

While retrieving data from SQL Server, you can always create the format as required by implementing your own logic. Only you need to make changes in the SELECT statement. DATENAME() and DATEPART() function can be used to achieve this.
Check this-


SQL
SELECT DATENAME(MONTH,GETDATE())+' '+CAST(DATEPART(DAY,GETDATE()) AS VARCHAR)

OUTPUT:
Result
--------
August 5


If you want the month name to be in lower case then use LOWER() function as follows-
SQL
SELECT LOWER(DATENAME(MONTH,GETDATE()))+' '+CAST(DATEPART(DAY,GETDATE()) AS VARCHAR) AS Result

OUTPUT:
Result
--------
august 5


Hope, it helps :)

 
Share this answer
 
v3
Comments
raviram123 6-Aug-15 4:37am    
sir what u have submitted is nice but what i want is already i have entered some records in to database which contains birthday images and Current date column with datatype date so when i inserted from ui i have inserted like 1985-08-06 so my sys date is like 2015-08-06 so images related to this date is coming but not 1985-08-06 so plz give my idea
raviram123 6-Aug-15 4:38am    
Modify the comment. Delete the comment.
sir what u have submitted is nice but what i want is already i have entered some records in to database which contains birthday images and Current date column with datatype date so when i inserted from ui i have inserted like 1985-08-06 so my sys date is like 2015-08-06 so images related to this date is coming but not 1985-08-06 so plz give me any idea

Please, read my comment to the question.


It's very important to use proper data type. Date is a date, not string! In other words: Why to use conversion, when you can filter data using proper data type?



[EDIT]
Assuming that you want to fetch data related to current month and day, use query like this:
SQL
SELECT <Field_list>
FROM YourTableName
WHERE Month(DateField) = Month(GETDATE()) AND Day(DateField) = Day(GETDATE())


This is the way to ignore a year part of date.

More:
MONTH (Transact-SQL)[^]
DAY (Transact-SQL)[^]
GETDATE (Transact-SQL)[^]
 
Share this answer
 
v2
Comments
raviram123 6-Aug-15 4:38am    
Modify the comment. Delete the comment.
sir what u have submitted is nice but what i want is already i have entered some records in to database which contains birthday images and Current date column with datatype date so when i inserted from ui i have inserted like 1985-08-06 so my sys date is like 2015-08-06 so images related to this date is coming but not 1985-08-06 so plz give my idea
Maciej Los 6-Aug-15 4:51am    
Please, see updatef answer.

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