We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a1199c7 commit 5ade648Copy full SHA for 5ade648
7 files changed
mysql-test/r/func_time.result
@@ -468,6 +468,23 @@ select date_add(time,INTERVAL 1 SECOND) from t1;
468
date_add(time,INTERVAL 1 SECOND)
469
2006-07-08 00:00:01
470
drop table t1;
471
+select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
472
+last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
473
+last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
474
+last_day('2001-02-12');
475
+f1 f2 f3 f4 f5 last_day(NULL) last_day('2001-02-12')
476
+2000-02-29 2002-12-31 NULL 2003-04-30 2001-01-31 NULL 2001-02-28
477
+create table t1 select last_day('2000-02-05') as a;
478
+describe t1;
479
+Field Type Null Key Default Extra
480
+a date 0000-00-00
481
+select * from t1;
482
+a
483
+2000-02-29
484
+drop table t1;
485
+select last_day('2000-02-05');
486
+last_day('2000-02-05')
487
488
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
489
strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0
490
1
mysql-test/t/func_time.test
@@ -224,6 +224,19 @@ select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
224
select date_add(time,INTERVAL 1 SECOND) from t1;
225
226
227
+# test for last_day
228
229
+ last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
230
+ last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
231
+ last_day('2001-02-12');
232
+
233
234
235
236
237
238
239
240
# Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that
241
# TZ variable set to GMT-3
242
sql/item_create.cc
@@ -707,3 +707,8 @@ Item *create_func_str_to_date(Item* a,Item* b)
707
{
708
return new Item_func_str_to_date(a, b);
709
}
710
711
+Item *create_func_last_day(Item *a)
712
+{
713
+ return new Item_func_last_day(a);
714
+}
sql/item_create.h
@@ -150,3 +150,4 @@ Item *create_func_subtime(Item* a,Item* b);
150
Item *create_func_timediff(Item* a,Item* b);
151
Item *create_func_maketime(Item* a,Item* b,Item* c);
152
Item *create_func_str_to_date(Item* a,Item* b);
153
+Item *create_func_last_day(Item *a);
sql/item_timefunc.cc
@@ -2310,3 +2310,19 @@ String *Item_func_str_to_date::val_str(String *str)
2310
return str;
2311
return 0;
2312
2313
2314
2315
+String *Item_func_last_day::val_str(String *str)
2316
2317
+ TIME ltime;
2318
+ if (!get_arg0_date(<ime,0))
2319
+ {
2320
+ uint month_idx= ltime.month-1;
2321
+ ltime.day= days_in_month[month_idx];
2322
+ if ( month_idx == 1 && calc_days_in_year(ltime.year) == 366)
2323
+ ltime.day+= 1;
2324
+ if (!make_datetime(DATE_ONLY, <ime, str))
2325
+ return str;
2326
+ }
2327
+ return 0;
2328
sql/item_timefunc.h
@@ -809,3 +809,21 @@ class Item_func_str_to_date :public Item_date_func
809
max_length=MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
810
811
};
812
813
+class Item_func_last_day :public Item_str_func
814
815
+public:
816
+ Item_func_last_day(Item *a) :Item_str_func(a) {}
817
+ String *val_str(String *str);
818
+ const char *func_name() const { return "last_day"; }
819
+ enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
820
+ void fix_length_and_dec()
821
822
+ decimals=0;
823
+ max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
824
825
+ Field *tmp_table_field(TABLE *t_arg)
826
827
+ return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
828
829
+};
sql/lex.h
@@ -551,7 +551,8 @@ static SYMBOL sql_functions[] = {
551
{ "IS_FREE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_free_lock)},
552
{ "IS_USED_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_used_lock)},
553
{ "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0},
554
- { "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)},
+ { "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)},
555
+ { "LAST_DAY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_last_day)},
556
{ "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
557
{ "LEAST", SYM(LEAST_SYM),0,0},
558
{ "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},
0 commit comments