数据库中有一个字段userbirth是datetime类型,如何用datediff算出一个用户的当前的年龄;比如如出生在1984.07.24,到目前的年龄,应该怎么写?

解决方案 »

  1.   

    DateDiff specifics a number of time intervals between two dates. 
    DateDiff (interal,date1,date2,firstdayofweek,firstweekofyear)      Interval 
                yyyy = year 
                q = quarter 
                m = month 
                y = day of year 
                d = day 
                w = weekday 
                ww = week 
                h = hour 
                n = minute 
                s = second 
         date1 and date2 are used to calculate the interval 
         firstdayofweek is sunday unless specified 
         firstweekofyear is jan 1 unless specified 
    Weekday returns a number representing the day of the week.      Return values are: 
                Sunday = 1 
                Monday = 2 
                Tuesday = 3 
                Wednesday = 4 
                Thursday = 5 
                Friday = 6 
                Saturday = 7 First determine the number of days between the two dates. Calculating the number of work days is done by not adding Saturday and Sunday dates. A query extract from a table containing all the holidays for the year could also be added for increased accuracy. 
      

  2.   

    当前时间可以用getdate(),也可以用now()
      

  3.   

    何必用datadiff,直接取出年份比较不方便些么?
      

  4.   

    上面的那个,能不能帮我写一下,就是在18-20岁的,满足这个条件的,把的username
      

  5.   

    PPLUNCLE(人最可怕的是没有了方向) 
    你的意思是怎么写?
      

  6.   

    yearDiff  = DateDiff("y", DateTime.parse(dr["userbirth"]), DateTime.Now)