str-to-date

More than 60 seconds or minutes in MySQL import file

隐身守侯 提交于 2020-01-06 03:41:29
问题 I'm currently importing a CSV file to a MySQL table, with lines like: 2/28/2015 8:46:30 PM,1:40,2,1234567,1435.6071 2/28/2015 8:45:58 PM,0:19,1,1234568,1435.6436 It's basically a CDR from a PBX. However, I don't have control of info source, so I just receive this file as is. So far, columns are: DATE,DURATION,MINUTES,PHONE,BALANCE I've used LOAD DATA INFILE to import my data, like this: LOAD DATA INFILE '10811.csv' INTO TABLE cdr fields terminated by ',' lines terminated by '\n' (@col1, @col2

Why is TFormatSettings not behaving as expected?

我的梦境 提交于 2020-01-03 06:58:06
问题 I expect the following code to work: program Project3; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; var FS: TFormatSettings; const DF = 'yyyymmdd'; begin try WriteLn(FormatDateTime(DF, Now)); FS := TFormatSettings.Create; FS.ShortDateFormat := DF; WriteLn(StrToDate('20121219', FS)); ReadLn; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Why is it throwing an exception, saying that '20121219' is not a valid date? Isn't that exactly what passing the

wordpress - Sortable custom fields columns

99封情书 提交于 2020-01-03 05:14:10
问题 I added some custom fields (dates) in my admin columns. I try to make them sortable but in order to do that I need to convert them from string to date. My naive and simple code obviously doesn't work... Can someone point out my error(s) ? add_action( 'pre_get_posts', 'orderby_date' ); function orderby_date( $query ) { $orderby = $query->get( 'orderby'); if( 'start' == $orderby ) { $query->set('meta_key','class_start'); $query->set('orderby',"STR_TO_DATE(meta_value,'%m/%d/%Y')"); } } 回答1: This

STR_TO_DATE and ISO8601 Atomtime format

落爺英雄遲暮 提交于 2019-12-24 10:51:02
问题 I have a MySQL database, which I cannot alter, where I read date from. The issue is that I have a varchar column that stores a date. The date is stored in the atomtime format eg. 2014-06-01T00:00:00+02:00 . I cannot figure how to specify the format in the STR_TO_DATE function. I tried STR_TO_DATE(Endtime, '%Y-%m-%dT%H:%i:%s+02:00') , but that doesn't work. Do anyone have a solution for this? I am trying to run the following query (which is not working properly): SELECT *, COUNT(*) as antal

Inserting date value into MySQL through PHP

匆匆过客 提交于 2019-12-23 05:37:14
问题 What I'm trying to do is as the title implies inserting date into created table. I've done my research. I considered following topics: Parse error: syntax error, unexpected T_VARIABLE on line 107 SQL DML: Incorrect date value (MySQL) and others. However nothing really helped to solve this. The $dob variable is in there on purpose. I need to make sure that it will change as users will change as well. This is my php code: $firstName = $middleName = $lastName = $mobileNumber = $dob = $address =

mysql STR_TO_DATE not working

夙愿已清 提交于 2019-12-22 09:19:51
问题 I have a table with a varchar column called birthday CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `birthday` varchar(30) COLLATE utf16_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci AUTO_INCREMENT=5 ; INSERT INTO `test` (`id`, `birthday`) VALUES (1, '20041225'), (2, '2004-12-25'), (3, '19941225'), (4, '19941201'); I try to run this query: SELECT str_to_date(birthday,"%Y%m%d") FROM `test` WHERE 1 But it always

Can't create mysql table due to Incorrect datetime value “…” for function str_to_date

拥有回忆 提交于 2019-12-14 03:58:25
问题 The following query works select date(str_to_date("08-Nov-2005 22:07","%d-%M-%Y %H:%i:%S")) As expected, it returns 2005-11-08 The following query also works select date(str_to_date("XXXX","%d-%M-%Y %H:%i:%S")) As expected, it returns NULL I should note there is a warning, but it doesn't stop the query from executing and returning a NULL result show warnings yields But the problem occurs when I try to create a table from the result. This works CREATE TABLE myTable AS select date(str_to_date(

Error Code: 1411. Incorrect datetime value: '0000-00-00' for function str_to_date

一世执手 提交于 2019-12-13 02:38:18
问题 I'm trying to change the format of a date from a CSV file before insert. I created a trigger BEFORE INSERT but it doesn't seem to work. CREATE TABLE items ( item_id int(11) NOT NULL AUTO_INCREMENT, price_list_id int(11) NOT NULL, sku varchar(20) NOT NULL, description varchar(45) DEFAULT NULL, cost float NOT NULL DEFAULT '0', notes varchar(45) DEFAULT NULL, discount_factor float DEFAULT '1', start_date date DEFAULT NULL, end_date date DEFAULT NULL, PRIMARY KEY (item_id,sku), KEY price_list_id

mysql STR_TO_DATE not working

余生颓废 提交于 2019-12-05 21:51:24
I have a table with a varchar column called birthday CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `birthday` varchar(30) COLLATE utf16_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci AUTO_INCREMENT=5 ; INSERT INTO `test` (`id`, `birthday`) VALUES (1, '20041225'), (2, '2004-12-25'), (3, '19941225'), (4, '19941201'); I try to run this query: SELECT str_to_date(birthday,"%Y%m%d") FROM `test` WHERE 1 But it always return rows with null values. If I run the query: SELECT str_to_date('20141225',"%Y%m%d") FROM `test`