[Help]Time format

03/31/2015 00:41 banktakung#1
how to convert time 20150331031428 to normal datetime with php code sir.

:handsdown::handsdown:
03/31/2015 01:14 xTwiLightx#2
In PHP, substr() is your weapon of choice:
[Only registered and activated users can see links. Click Here To Register...]

PHP Code:
$rawtime '20150331031428'// unconverted datetime string

$year substr($rawtime04);
$month substr($rawtime42);
$day substr($rawtime62);
$hour substr($rawtime82);
$minute substr($rawtime102);
$second substr($rawtime122);

// stick them all together to get your datetime format
$datetime "$year-$month-$day $hour:$minute:$second.000"// .000 is optional. 

But you can do it much more easy when you use SQL functions:
Code:
CREATE function [dbo].[getdatetime]
( 
	@s_date	varchar(14)
)  
returns varchar(19)
as

begin

declare @c_date varchar(19)

	select @c_date =	convert(varchar(19),
							substring(@s_date,1,4) + '-' +
							substring(@s_date,5,2) + '-' +
							substring(@s_date,7,2) + ' ' +
							substring(@s_date,9,2) + ':' +
							substring(@s_date,11,2) + ':' +
							CASE substring(@s_date,13,2) WHEN '' THEN '00' ELSE substring(@s_date,13,2) END
						)
	return @c_date 
end

You can get the actual datetime like that:
Code:
select dbo.getdatetime('20150331031428') as convdate
[Only registered and activated users can see links. Click Here To Register...]



So, if you are getting logs from LOGGING_01_DBF, you can do it like this:

This is my latest item log with (unconverted) s_date column.

[Only registered and activated users can see links. Click Here To Register...]

Rewrite the query to use the function.

[Only registered and activated users can see links. Click Here To Register...]


Easily done. ;)
03/31/2015 16:13 banktakung#3
Quote:
Originally Posted by xTwiLightx View Post
In PHP, substr() is your weapon of choice:
[Only registered and activated users can see links. Click Here To Register...]

PHP Code:
$rawtime '20150331031428'// unconverted datetime string

$year substr($rawtime04);
$month substr($rawtime42);
$day substr($rawtime62);
$hour substr($rawtime82);
$minute substr($rawtime102);
$second substr($rawtime122);

// stick them all together to get your datetime format
$datetime "$year-$month-$day $hour:$minute:$second.000"// .000 is optional. 

But you can do it much more easy when you use SQL functions:
Code:
CREATE function [dbo].[getdatetime]
( 
	@s_date	varchar(14)
)  
returns varchar(19)
as

begin

declare @c_date varchar(19)

	select @c_date =	convert(varchar(19),
							substring(@s_date,1,4) + '-' +
							substring(@s_date,5,2) + '-' +
							substring(@s_date,7,2) + ' ' +
							substring(@s_date,9,2) + ':' +
							substring(@s_date,11,2) + ':' +
							CASE substring(@s_date,13,2) WHEN '' THEN '00' ELSE substring(@s_date,13,2) END
						)
	return @c_date 
end

You can get the actual datetime like that:
Code:
select dbo.getdatetime('20150331031428') as convdate
[Only registered and activated users can see links. Click Here To Register...]



So, if you are getting logs from LOGGING_01_DBF, you can do it like this:

This is my latest item log with (unconverted) s_date column.

[Only registered and activated users can see links. Click Here To Register...]

Rewrite the query to use the function.

[Only registered and activated users can see links. Click Here To Register...]


Easily done. ;)
Thank you so much :)