mysql如何获取周的起始时间和结束时间

直接上代码

SELECT
	DATE_FORMAT(
		str_to_date(
			'2019-04-28 18:23:11',
			'%Y-%m-%d %k:%i:%s'
		),
		'%Y-%m-%d'
	) AS 'now day',
	CONCAT_WS(
		'-',
		from_unixtime(
			UNIX_TIMESTAMP(
				str_to_date(
					'2019-04-28 18:23:11',
					'%Y-%m-%d %k:%i:%s'
				)
			) - WEEKDAY(
				str_to_date(
					'2019-04-28 18:23:11',
					'%Y-%m-%d %k:%i:%s'
				)
			) * 86400,
			'%m.%d'
		),
		from_unixtime(
			UNIX_TIMESTAMP(
				str_to_date(
					'2019-04-28 18:23:11',
					'%Y-%m-%d %k:%i:%s'
				)
			) + (
				7 - (
					WEEKDAY(
						str_to_date(
							'2019-04-28 18:23:11',
							'%Y-%m-%d %k:%i:%s'
						)
					) + 1
				)
			) * 86400,
			'%m.%d'
		)
	) AS 'target day'

 

你可能感兴趣的:(数据库)