• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

sql date query

Hey guys i have a table and want to find out if my voucher is Expired or not in a sql query

i have a coloum called deal_end which as varchar(50) data type

and the format the date is entered is like this 13.07.2012  which goes date month year


now i need a sql query to select all records where the deal_end <= todays date ?


please help
0
JCWEBHOST
Asked:
JCWEBHOST
1 Solution
 
kristof1104Commented:
rewriting ansewer just a sec
0
 
JCWEBHOSTAuthor Commented:
SELECT SUBSTRING(description, 0, 40) as description, voucher_code, u_first_name, u_last_name from groupon


the where statement i am having problem
0
 
EvilPostItCommented:
SELECT * FROM TABLE WHERE CONVERT(DATETIME,deal_end,104)<=getdate()
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
jonnidipCommented:
You can cast your value to date:
declare @test as table
(
	dt varchar(50)
)

insert into @test
select '31.12.2011'
insert into @test
select '01.06.2012'
insert into @test
select '31.12.2012'

select dt from @test
where cast(dt as date) < getdate()

Open in new window

0
 
Lee SavidgeCommented:
where convert(datetime, deal_end, 104) <= getdate()
0
 
deightonprogCommented:
you could run into trouble casting date strings in UK format into DATETIME

how about
SELECT * FROM (
     SELECT * FROM (
             select *,  substring(deal_end,7,4) + substring(deal_end,4,2) + left(deal_end,2) DS   from    groupon) SQ 
          WHERE ISDATE(SQ.DS) = 1) SQ2 
WHERE CAST(SQ2.DS AS DATETIME) <= getdate()

Open in new window

0
 
Lara FEACommented:
You can use dateformat to specify format you use

Here is sample
SET DATEFORMAT dmy
GO
DECLARE @datevar varchar(50)
set @datevar= '10.11.2012'
SELECT CONVERT(varchar(50), convert(datetime,@datevar),109)

SET DATEFORMAT mdy
SELECT CONVERT(varchar(50), convert(datetime,@datevar),109)

set @datevar  = '10.11.12'
SET DATEFORMAT ydm
SELECT CONVERT(varchar(50), convert(datetime,@datevar),109)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now