# `FUN_GET_DATE_BC_STARTDATE_NEWTYPE` (function)

> 根据传入时间获取时间


- **Type:** FUNCTION
- **Returns:** `datetime`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_Date` | `datetime` |
| 2 | IN | `p_sWorkType` | `varchar(1)` |
| 3 | IN | `p_sWorkStart` | `varchar(200)` |
| 4 | IN | `p_sWorkOff` | `varchar(200)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `FUN_GET_DATE_BC_STARTDATE_NEWTYPE`'`._

## Narrative

**Business context:** Variant of [`FUN_GET_DATE_BC_STARTDATE_NEW`](FUN_GET_DATE_BC_STARTDATE_NEW.md) that branches on shift type. For two-shift mode (`sWorkType=2`), snaps the input to whichever shift it falls into. For day-shift mode (`sWorkType=1`), instead returns the next day's clock-on when the input is in the late-evening window (≥20:00). Used by manufacturing time-set and MES event-report procs that need shift-anchoring sensitive to whether the shop runs single or double shifts.

**What it does:** `IF sWorkType=2`: returns today's `sWorkStart` when `HOUR(p_Date)` is in the active window; otherwise returns either today's `sWorkOff` (when past 20:00) or yesterday's `sWorkOff`. `ELSE` (day-shift): returns today's `sWorkStart` when in-window; otherwise tomorrow's `sWorkStart` when `HOUR ≥ 20`, else today's `sWorkStart`.

**Invocation:** called by `Sp_BtnCalculation_Machine_time_byMachineType` (machine-time recalc on schedule button), `Sp_Mes_EventReport`, and `Sp_Mes_EventReportOld`. MES event-reporting and machine-time recalc chain. Body of [`FUN_GET_DATE_BC_STARTDATE_NEW`](FUN_GET_DATE_BC_STARTDATE_NEW.md) is referenced from the same source bundle.
