views:

102

answers:

3

Hi guys could you please help me with this. I know it is silly but can't find unswer anywhere:

I have a query that shows events from the today time_stamp but I want to include today as well. How do I add this to this query?

 ...
WHERE events.event_date > current_timestamp
ORDER BY convert (event_date, date) ASC

As it is formed it doesn't show the event of the day. Hope I made it clear. Please help me many thanks. F

A: 

If i understand correctly current_timestamp is a datetime containing hh:mm:ss.

To get the date only use

DATEADD(dd,0, DATEDIFF(dd,0current_timestamp))

Which should get youjust the Day Month Year value.

Then you can change your code to

WHERE events.event_date >= DATEADD(dd,0, DATEDIFF(dd,0current_timestamp))
ORDER BY convert (event_date, date) ASC
astander
Hi astander. it is a yyyy/mm/dd date. What I need is simply to show the today event as well. As it is formed my query does not show the today event because is already passed.
francesco
What DB are you using? Sql Server?
astander
I ma using MySql database
francesco
OK, can yuo extract the date part from the current_timestamp? is so, use that date and change the > to >=
astander
It does show this way but it keeps showing for all events more then one days old.. That's I need to show the today event but until 24.00 hours. So i don't want to show the today event tomorrow.Not sure I am doing something wrong.
francesco
Hi Astander, do you know what will be the compatible for CONVERT(varchar(10),current_timestamp,101) in MySql. Will it be CONVERT(@StartDate, CHAR(10)) ?I don't know ... if you know please help the OP
priyanka.sarkar
I searched in the net but only came up with CONVERT(@StartDate, CHAR(10)). Also I have no experience in MySql. If you have so or if you know pls help him. Sorry if I made any mistake by asking u in this way. My intension is to help the OP. Because I guess he is struggling a lot (:
priyanka.sarkar
Have you tried using the DATE() function?
astander
+1  A: 

Try this

declare @t table(eventdt datetime)
insert into @t 
    select '12/12/2009' union all 
    select '12/15/2009'union all 
    select '11/27/2009'union all -- today's date
    select '11/26/2009' union all
    select '10/26/2009'
select * from @t where eventdt > =  CONVERT(varchar(10),current_timestamp,101)

Output:

eventdt
2009-12-12 00:00:00.000
2009-12-15 00:00:00.000
2009-11-27 00:00:00.000
priyanka.sarkar
I have tried this but it doesn't seem to work.
francesco
I have modified and it is working
priyanka.sarkar
Sorry pewed it doesn't work on my. My query is as follow:SELECT event_ID, DATE_FORMAT(events.event_date, '%W, %D %M %Y') AS event_dateFROM eventsWHERE events.event_date >= current_timestampORDER BY convert (event_date, date) ASC
francesco
Just confirm me if CONVERT(varchar(10),current_timestamp,101) works in mysql or not. I am a sql server guy. I thought the same will work for mysql too!
priyanka.sarkar
NO it doesn't. It gives me an error.
francesco
Can you please post the error
priyanka.sarkar
See , I searched in the net to find a similar function as CONVERT(varchar(10),current_timestamp,101) and I got CONVERT(current_timestamp, CHAR(8)) from http://forums.mysql.com/read.php?98,51791,51793#msg-51793.The program I have given is 100% working in Sql Server but may need to modify only CONVERT(varchar(10),current_timestamp,101) in my sql.Try my program first after making that portion compatible to mysql and then implement that in your program. I am confident that you can do it and will get success
priyanka.sarkar
A: 

for anybody who might have the same problem I sorlved it as follow:

 WHERE events.event_date > current_timestamp 
 OR TIMESTAMPDIFF(DAY, events.event_date, CURRENT_TIMESTAMP) = 0 
 ORDER BY convert (event_date, date) ASC ";
francesco