<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[My Visual Database — Преобразование даты]]></title>
		<link>https://myvisualdatabase.com/forum/viewtopic.php?id=9133</link>
		<atom:link href="https://myvisualdatabase.com/forum/extern.php?action=feed&amp;tid=9133&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Преобразование даты.]]></description>
		<lastBuildDate>Fri, 17 Jan 2025 12:58:41 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Преобразование даты]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=51944#p51944</link>
			<description><![CDATA[<p>Огромное Вам спасибо!<br />Все отлично работает!</p>]]></description>
			<author><![CDATA[null@example.com (Vickus)]]></author>
			<pubDate>Fri, 17 Jan 2025 12:58:41 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=51944#p51944</guid>
		</item>
		<item>
			<title><![CDATA[Re: Преобразование даты]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=51942#p51942</link>
			<description><![CDATA[<div class="quotebox"><cite>Vickus wrote:</cite><blockquote><p>Спасибо!<br />Я не специалист. Просто пытаюсь разобраться и что-то внедрять. Можете подсказать как объединить вашу функцию и часть кода?</p></blockquote></div><div class="codebox"><pre><code>function DateConv(AValue:string):string;
begin
  try
    Result := FormatDateTime(&#039;YYYY-MM-DD&#039;,StrToDate(AValue));
  except
    Result := AValue;
  end;
end;

procedure Frm_Import_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
Excel : Variant ;
Sheet : Variant ;
rows, columns : Integer;
MaxRow : Integer;
MaxCol : Integer;
result_string : string;
sql_string : string ;
irows : integer ;
begin
    Excel:=CreateOleObject(&#039;Excel.Application&#039;);
    //Excel.Visible:= True;
    Excel.Workbooks.Open(Frm_Import.Edit1.Text) ;
    Sheet := Excel.WorkSheets[1] ;
    MaxRow := Sheet.Usedrange.EntireRow.count ;
    MaxCol := sheet.Usedrange.EntireColumn.count;
    //special excel[row,column]
    irows := 0 ;
    For  rows := 2 To  MaxRow Do
    Begin
        For  columns := 1 To Maxcol Do
        Begin
            result_string := result_string + &#039;&quot;&#039;+DateConv(Excel.ActiveSheet.Cells[rows,columns].Value)+&#039;&quot;,&#039;
        End;
        sql_string := &#039;INSERT IGNORE INTO Main(id,surname,firstname,patronymic,contract,doplata_cb,doplata,cert_num,ngroup,id_Program,active,data_deactive) values (&#039;+
        copy(result_string,1, Length(result_string)-1)+&#039;);&#039;;
        Frm_Import.Memo1.Lines.Add(sql_string) ;
        irows := irows +1 ;
        result_string := &#039;&#039; ;
        sql_string := &#039;&#039; ;
        Frm_Import.Label1.Caption := IntToStr(irows);
    End;
// deleted past about kill excel
        Application.ProcessMessages;
        Excel.Workbooks.Close;
        KillTask(&#039;EXCEL.EXE&#039;);
end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (k245)]]></author>
			<pubDate>Fri, 17 Jan 2025 11:22:31 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=51942#p51942</guid>
		</item>
		<item>
			<title><![CDATA[Re: Преобразование даты]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=51935#p51935</link>
			<description><![CDATA[<p>Спасибо!<br />Я не специалист. Просто пытаюсь разобраться и что-то внедрять. Можете подсказать как объединить вашу функцию и часть кода?</p><div class="quotebox"><cite>k245 wrote:</cite><blockquote><p>Вам пригодится функция, которая конвертирует дату в нужный формат, а остальные данные оставляет без изменений</p><div class="codebox"><pre><code>function DateConv(AValue:string):string;
begin
  try
    Result := FormatDateTime(&#039;YYYY-MM-DD&#039;,StrToDate(AValue));
  except
    Result := AValue;
  end;
end;</code></pre></div><p>используйте её здесь:</p><div class="codebox"><pre><code>...
        For  columns := 1 To Maxcol Do
        Begin
            result_string := result_string + &#039;&quot;&#039;+DateConv(Excel.ActiveSheet.Cells[rows,columns].Value)+&#039;&quot;,&#039;
        End;
...</code></pre></div></blockquote></div>]]></description>
			<author><![CDATA[null@example.com (Vickus)]]></author>
			<pubDate>Tue, 14 Jan 2025 10:21:01 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=51935#p51935</guid>
		</item>
		<item>
			<title><![CDATA[Re: Преобразование даты]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=51899#p51899</link>
			<description><![CDATA[<p>Вам пригодится функция, которая конвертирует дату в нужный формат, а остальные данные оставляет без изменений</p><div class="codebox"><pre><code>function DateConv(AValue:string):string;
begin
  try
    Result := FormatDateTime(&#039;YYYY-MM-DD&#039;,StrToDate(AValue));
  except
    Result := AValue;
  end;
end;</code></pre></div><p>используйте её здесь:</p><div class="codebox"><pre><code>...
        For  columns := 1 To Maxcol Do
        Begin
            result_string := result_string + &#039;&quot;&#039;+DateConv(Excel.ActiveSheet.Cells[rows,columns].Value)+&#039;&quot;,&#039;
        End;
...</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (k245)]]></author>
			<pubDate>Thu, 26 Dec 2024 09:14:22 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=51899#p51899</guid>
		</item>
		<item>
			<title><![CDATA[Преобразование даты]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=51896#p51896</link>
			<description><![CDATA[<p>Добрый день!<br />Помогите, пожалуйста. Использую скрипт для импорта данных из Excel. В файле Excel каждый раз приходится даты из формата (24.12.2024) переводить в формат (2024-24-12). Возможно ли, чтобы в этом скрипте даты конвертировались автоматически?<br />Приложил скриншот формы и ссылку на файл Excel (<a href="https://disk.yandex.ru/i/4vTvT8ztAsJ1qQ">https://disk.yandex.ru/i/4vTvT8ztAsJ1qQ</a>)<br />Спасибо.</p><p>//********************//</p><p>procedure Frm_Import_Button1_OnClick (Sender: TObject; var Cancel: boolean);<br />var<br />opendialog : Topendialog ;<br />begin<br />&nbsp; &nbsp; opendialog := Topendialog.Create(Frm_Import) ;<br />&nbsp; &nbsp; IF opendialog.execute Then<br />&nbsp; &nbsp; Frm_Import.Edit1.Text := opendialog.filename ;<br />&nbsp; &nbsp; opendialog.free;<br />end;</p><p>//********************//</p><p>procedure Frm_Import_Button2_OnClick (Sender: TObject; var Cancel: boolean);<br />var<br />Excel : Variant ;<br />Sheet : Variant ;<br />rows, columns : Integer;<br />MaxRow : Integer;<br />MaxCol : Integer;<br />result_string : string;<br />sql_string : string ;<br />irows : integer ;<br />begin<br />&nbsp; &nbsp; Excel:=CreateOleObject(&#039;Excel.Application&#039;);<br />&nbsp; &nbsp; //Excel.Visible:= True;<br />&nbsp; &nbsp; Excel.Workbooks.Open(Frm_Import.Edit1.Text) ;<br />&nbsp; &nbsp; Sheet := Excel.WorkSheets[1] ;<br />&nbsp; &nbsp; MaxRow := Sheet.Usedrange.EntireRow.count ;<br />&nbsp; &nbsp; MaxCol := sheet.Usedrange.EntireColumn.count;<br />&nbsp; &nbsp; //special excel[row,column]<br />&nbsp; &nbsp; irows := 0 ;<br />&nbsp; &nbsp; For&nbsp; rows := 2 To&nbsp; MaxRow Do<br />&nbsp; &nbsp; Begin<br />&nbsp; &nbsp; &nbsp; &nbsp; For&nbsp; columns := 1 To Maxcol Do<br />&nbsp; &nbsp; &nbsp; &nbsp; Begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result_string := result_string + &#039;&quot;&#039;+Excel.ActiveSheet.Cells[rows,columns].Value+&#039;&quot;,&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; End;<br />&nbsp; &nbsp; &nbsp; &nbsp; sql_string := &#039;INSERT IGNORE INTO Main(id,surname,firstname,patronymic,contract,doplata_cb,doplata,cert_num,ngroup,id_Program,active,data_deactive) values (&#039;+<br />&nbsp; &nbsp; &nbsp; &nbsp; copy(result_string,1, Length(result_string)-1)+&#039;);&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; Frm_Import.Memo1.Lines.Add(sql_string) ;<br />&nbsp; &nbsp; &nbsp; &nbsp; irows := irows +1 ;<br />&nbsp; &nbsp; &nbsp; &nbsp; result_string := &#039;&#039; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; sql_string := &#039;&#039; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; Frm_Import.Label1.Caption := IntToStr(irows);<br />&nbsp; &nbsp; End;<br />// deleted past about kill excel<br />&nbsp; &nbsp; &nbsp; &nbsp; Application.ProcessMessages;<br />&nbsp; &nbsp; &nbsp; &nbsp; Excel.Workbooks.Close;<br />&nbsp; &nbsp; &nbsp; &nbsp; KillTask(&#039;EXCEL.EXE&#039;);<br />end;</p><p>//********************//</p><br /><p>procedure Frm_Import_Button3_OnClick (Sender: TObject; var Cancel: boolean);<br />var<br />i_sql : integer ;<br />begin<br />&nbsp; &nbsp; For i_sql := 0 To Strtoint(Frm_Import.Label1.Caption) -1 Do<br />&nbsp; &nbsp; Begin<br />&nbsp; &nbsp; &nbsp; &nbsp; SQLExecute(Frm_Import.Memo1.Lines[i_sql]) ;<br />&nbsp; &nbsp; &nbsp; &nbsp; Frm_Import.Label2.Caption := IntToStr(i_sql+1) ;<br />&nbsp; &nbsp; &nbsp; &nbsp; Frm_Import.Label3.Caption := FormatFloat(&#039;0.00&#039;,(i_sql+1)/StrTOInt((Frm_Import.Label1.Caption))*100)+&#039; %&#039; ;<br />&nbsp; &nbsp; &nbsp; &nbsp; Application.ProcessMessages;<br />&nbsp; &nbsp; End;<br />&nbsp; &nbsp; Application.ProcessMessages;<br />&nbsp; &nbsp; FrmMain.Table_Main.dbUpdate;<br />&nbsp; &nbsp; Frm_Import.Edit1.Clear;<br />&nbsp; &nbsp; Frm_Import.Memo1.Clear;<br />&nbsp; &nbsp; Frm_Import.Label1.Caption :=&#039;0&#039;;<br />&nbsp; &nbsp; Frm_Import.Label2.Caption :=&#039;0&#039;;<br />&nbsp; &nbsp; Frm_Import.Label3.Caption :=&#039;0.0%&#039;;<br />&nbsp; &nbsp; Frm_Import.Close;<br />end;</p><p>//********************//</p>]]></description>
			<author><![CDATA[null@example.com (Vickus)]]></author>
			<pubDate>Wed, 25 Dec 2024 07:06:30 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=51896#p51896</guid>
		</item>
	</channel>
</rss>
