SQL Server:
select case when (datepart(hour,GETDATE())>=0 and datepart(hour,GETDATE())<12)
then 1 else 0 end as 上午,
case when (datepart(hour,getdate())>12 and datepart(hour,getdate())<23)
then 1 else 0 end as 下午
Java
try {
GregorianCalendar ca = new GregorianCalendar();
ca.setTime(new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse("2016-07-28 11:04:36"));
YYRQDM = ca.get(GregorianCalendar.AM_PM) + 1;
} catch (ParseException e) {
e.printStackTrace();
}