[英]calculation of expiration dates with sql
my first time doing a date calculation on my system 我第一次在系统上进行日期计算
as you can see here on my first query how would i say that my expdate table is equal to this current date? 如您在此处的第一个查询中看到的,我怎么说我的过期表等于当前日期? then if so msgbox me "your item has expired"
然后,如果这样,msgbox我“您的商品已过期”
on my second query i wanted to set a msgbox where msgbox me three months before my expdate ? 在我的第二个查询中,我想设置一个msgbox,其中msgbox在我到期前三个月向我发送?
heres what i tried to do 这是我试图做的
cn.Open()
Dim query As String
query = "Select * from tblmeds where TIMESTAMPDIFF(MONTH,`expdate`,CURRENT_TIMESTAMP())< 1"
command = New MySqlCommand(query, cn)
readers = command.ExecuteReader
Dim count As Integer
count = 0
While readers.Read
count = count + 1
End While
cn.Close()
If count = 1 Then
msgbox "you have a expired items"
else
"no items are at risk"
PS:i am currently using PHPMYADMIN as my database PS:我当前正在使用PHPMYADMIN作为我的数据库
Assuming SQL SErver... 假设SQL服务器...
Subtract 3 months from the expiration date and compare that to the utc date (if multiple timezones are involved) otherwise you could just use getDate() 从到期日期减去3个月,然后将其与utc日期进行比较(如果涉及多个时区),否则可以使用getDate()
SELECT EXPDATE
FROM tblMeds
WHERE Dateadd(Month, -3,expDate) < = getutcdate()
If you change you query to 如果您更改查询到
query = "Select count(*) as cnt from tblmeds where TIMESTAMPDIFF(MONTH,`expdate`,CURRENT_TIMESTAMP())< 1"
Then you won't need a look to count the rows, the server can do that which is faster. 然后,您无需查看计数行数,服务器即可完成,这更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.