小弟想写一条sql语句:
insert into table1 (日期) values (?)
其中‘?’处想取系统当前年份加1,月和日都是1
比如现在是2004年,那么希望在表中插入2005-1-1
请问该如何实现?        由于我初次接触delphi,所以问题比较弱,不过还是提供了100分给回应的大侠!
多谢多谢!

解决方案 »

  1.   

    uses DateUtils;query1.sql.clear;
    query1.sql.add('insert into table1 (日期) values (:datetime)');
    query1.query1.ParamByName(日期) .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now(),1));
    query1.ExecSQL;
      

  2.   

    insert into table1 (日期) values (convert(datetime,convert(char(4),getdate(),102)+'0101'))
      

  3.   

    在SQL语句转换就行了,取服务器的时间
      

  4.   

    insert into table1 values(IntToStr(year(date+1))+'01'+'01')
      

  5.   

    insert into table1 (日期) values ( convert(datetime,convert(char(4),year(getdate())+1,102)+'0101') )
      

  6.   

    用字符串把日期给分割了,你想加多少都可以
    代码:
    var
     Year, Month, Day, DOW: Word;
     date:tdatetime;
     s1,s2:string;
      date:=DateTimePicker1.DateTime;
      DecodeDateFully(Date, Year, Month, Day, DOW);
      if month<10 then s1:='0'+inttostr(month) else s1:=inttostr(month);
      if Day<10 then s2:='0'+inttostr(Day)else s2:=inttostr(Day);
       suiedit5.Text:=inttostr(Year)+'-'+s1+'-'+s2;
      

  7.   

    delphi里有完整的日期时间增加的函数,如incyear incmonth incday inchour ...,将其转换后作参数给sql就行了。查查帮助
      

  8.   

    cdsgajxlp(新手) 的做法非常正确简捷,与采用什么样的数据库无关,值得肯定。
      

  9.   

    var sSQL :string;
        sDate :string;
        Year :word;
    begin
       Year :=YearOf(Date);
       sDate :=DateToStr(EncodeDate(Year,1,1));
       sSQL :='Insert into TableName (ColumnName...)Values('sDate');
      

  10.   

    sqlserver库,access库下面的就行
    uses DateUtils;with adoquery1 do
    try
      sql.clear;
      sql.add('insert into table1 (日期) values (:dt)');
      ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now   (),1));
      ExecSQL;
    except
      showmessage('插入失败!');
    end;
    如果access
    uses DateUtils;with adoquery1 do
    try
      sql.clear;
      sql.add('insert into table1 (日期) values (:dt)');
      ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now   (),1));
      ExecSQL;
    except
      showmessage('插入失败!');
    end;
      

  11.   

    这就行了
    with adoquery1 do
    try
      sql.clear;
      sql.add('insert into table1 (日期) values (:dt)');
      ParamByName('dt') .asstring:=formatdatetime('yyyy-01-01 00:00:01',Incyear(now),1));
      ExecSQL;
    except
      showmessage('插入失败!');
    end;
      

  12.   

    insert into table1 (日期) values (convert(datetime,convert(char(4),getdate(),102)+'0101'))