MySQL - Funcion que retorna Fecha en letras

 
Vista:
Imágen de perfil de Willian
Val: 2
Ha aumentado su posición en 60 puestos en MySQL (en relación al último mes)
Gráfica de MySQL

Funcion que retorna Fecha en letras

Publicado por Willian (52 intervenciones) el 19/11/2013 15:58:51
Hola Foristas quiero compartir esta funcion, en algun momento sera util en sus trabajos..
saludos desde Paraguay

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
DELIMITER $$
drop function if exists f_fecha_spanish$$
CREATE  FUNCTION f_fecha_spanish(v_fecha DATE,v_tipo int (3)) RETURNS varchar(50)
BEGIN
/*ejemplo de como Usar
mysql->select f_fecha_spanish('20130101',1);
resultado->'Martes'

mysql->select f_fecha_spanish('20130101',2);
resultado->'Enero'

mysql->select f_fecha_spanish('20130101',3);
resultado->'Martes 1 De Enero Del 2013'
*/
declare v_dia varchar(20);
declare v_mes varchar(20);
case v_tipo
	when 1 then
		case date_format(v_fecha,'%w')
			when 0 then
				set @fecha = 'Domingo';
			when 1 then
				set @fecha = 'Lunes';
			when 2 then
				set @fecha = 'Martes';
			when 3 then
				set @fecha = 'Miercoles';
			when 4 then
				set @fecha = 'Jueves';
			when 5 then
				set @fecha = 'Viernes';
			when 6 then
				set @fecha = 'Sábado';
		end case;
	when 2 then
		case date_format(v_fecha,'%m')
			when '01' then
				set @fecha = 'Enero';
			when '02' then
				set @fecha = 'Febrero';
			when '03' then
				set @fecha = 'Marzo';
			when '04' then
				set @fecha = 'Abril';
			when '05' then
				set @fecha = 'Mayo';
			when '06' then
				set @fecha = 'Junio';
			when '07' then
				set @fecha = 'Julio';
			when '08' then
				set @fecha = 'Agosto';
			when '09' then
				set @fecha = 'Septiembre';
			when '10' then
				set @fecha = 'Octubre';
			when '11' then
				set @fecha = 'Noviembre';
			when '12' then
				set @fecha = 'Diciembre';
		end case;
	when 3 then
		case date_format(v_fecha,'%w')
			when 0 then
				set @fecha = 'Domingo';
			when 1 then
				set @fecha = 'Lunes';
			when 2 then
				set @fecha = 'Martes';
			when 3 then
				set @fecha = 'Miercoles';
			when 4 then
				set @fecha = 'Jueves';
			when 5 then
				set @fecha = 'Viernes';
			when 6 then
				set @fecha = 'Sábado';
		end case;
		case date_format(v_fecha,'%m')
			when '01' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Enero Del ',year(v_fecha));
			when '02' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Febrero Del ',year(v_fecha));
			when '03' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Marzo Del ',year(v_fecha));
			when '04' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Abril Del ',year(v_fecha));
			when '05' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Mayo Del ',year(v_fecha));
			when '06' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Junio Del ',year(v_fecha));
			when '07' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Julio Del ',year(v_fecha));
			when '08' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Agosto Del ',year(v_fecha));
			when '09' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Septiembre Del ',year(v_fecha));
			when '10' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Octubre Del ',year(v_fecha));
			when '11' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Noviembre Del ',year(v_fecha));
			when '12' then
				set @fecha = concat(@fecha,' ',day(v_fecha), ' De Diciembre Del ',year(v_fecha));
		end case;
end case;
return(@fecha);
END $$
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder
Imágen de perfil de xve
Val: 796
Oro
Ha mantenido su posición en MySQL (en relación al último mes)
Gráfica de MySQL

Funcion que retorna Fecha en letras

Publicado por xve (1151 intervenciones) el 19/11/2013 18:18:56
Excelente William... muchas gracias!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar