0

I have a table in sql server 2008 r2. One of the fields in the table denotes how often a task runs. It is called everyMinutes. This field holds integer values, ranging from 0, to 15, to 120 and beyond. How can I select this field, and cast it as a time so that it may be added to other times?

I have startTime set as a time(7). I recognize I could do what I'm about to ask in sql. However my end goal is to do it in php.

I would like to query startTime as well as everyMinutes so that they can be easilly added together in php. I'm looking for to cast, or convert, or something everyMinutes in the select statement so this can be done.

mhopkins321
  • 2,993
  • 15
  • 56
  • 83

1 Answers1

1

You can use DateAdd:

select DATEADD (mi,  everyMinutes, '1/1/2005' )
from table

EDIT: If you want to do this in PHP, you can just select everyMinutes as is and then use strtotime:

strtotime('+ 30 minute',$yourdate);

(Sorry, I don't know php, but you just need to build a string using everyMinutes and use as the first param.)

See also: https://stackoverflow.com/a/1436844/1822514

Community
  • 1
  • 1
chue x
  • 18,573
  • 7
  • 56
  • 70
  • I'm querying this table and bringing it into php. Is there a way I can bring `everyMinutes` into the select statement as some flavor of datetime? – mhopkins321 Apr 22 '13 at 16:57
  • @mhopkins321 - Maybe I am missing something, but it doesn't make sense to have `everyMinutes` as a date time. How do you add two dates together (1/31/2005 + 2/15/2025 == ??) – chue x Apr 22 '13 at 17:02
  • I suppose I don't necessarily mean datetime. But rather some sort of type that has time in it. I have made an edit to my post above – mhopkins321 Apr 22 '13 at 17:06