Jump to content

converting a script from mysql to mssql - selecting dates


Poddy

Recommended Posts

Hello all, I'm having a problem with converting a script from MySQL to MSSQL

.. the problem is within this query:

 

select * from data  where  name LIKE '$name' AND spot LIKE '$line' AND piret LIKE '$piret' [b]AND timestamp >= '$before' AND timestamp <= '$after' ORDER BY timestamp DESC[/b]

 

the statement works until the bold part...

please note that all the variables except $before and $after are inserted with a '%'.

and before and after are built like this: 08/01/2008

i need it to select from dates between lets say 08/01/2008 and 08/03/2008 including those dates so records from the 1st, the 2nd and the 3rd will appear.. however i cannot get it to work

is there another way of making this statement?

 

the query does not fail, but does not return results.

 

also i have another issue:

 

SELECT * FROM data WHERE timestamp >= DATE_SUB(curdate(), INTERVAL 5 DAY) AND timestamp <= DATE_ADD(curdate(), INTERVAL 1 day) AND name LIKE '$name' AND spot LIKE '$line' AND piret LIKE '$piret' ORDER BY timestamp DESC "

 

i have this old line of code, but i cant find a function that works for me for current time, and subtract and add days that belong to mssql..

the function of that script is PHP recognizing the day of the week and the script chooses records of that week only.

 

Any help appriciated

Thanks in advance ???

Link to comment
Share on other sites

well i solved the first issue... using the BETWEEN statement and correcting the date format which for some reason i remembered it as a diffrent format.. my mistake.

 

However i still can't figure out how to SUB a date and ADD a date with days

i have tried this in the mssql console yet still not working

 

SELECT * FROM data WHERE timestamp BETWEEN dateadd(day, -6, '2008-01-08') AND '2008-03-08' AND name LIKE '$name' AND spot LIKE '$line' AND piret LIKE '$piret' ORDER BY timestamp DESC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.