# `FUN_GET_DATE_BC_STARTDATE` (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_sShiftsWork` | `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`'`._

## Narrative

**Business context:** Day-shift normalizer at the core of the production-scheduling time-math chain. For a day-shift machine, if the passed timestamp falls in the off-shift window, snaps it to the relevant clock-off boundary so all downstream interval math is shift-aligned. For two-shift mode (`sWorkType=2`) returns `p_Date` unchanged.

**What it does:** for `sWorkType=1`, classifies whether `p_Date` is in the off-shift window (`sWorkOff` → `sShiftsWork`). If yes, returns `today_sWorkOff` when `p_Date < today_sWorkOff`, else `tomorrow_sWorkOff`. Otherwise (and for non-day-shift) returns `p_Date`.

**Invocation:** core helper called by [`FUN_GET_CALCPLAN_DATE_END`](FUN_GET_CALCPLAN_DATE_END.md) and a wide span of production-scheduling and MES procs — BI workshop rollups (`Sp_bi_workshop_1/2/3`), board reports (`Sp_Bd_bi20_*`), machine-time calc (`Sp_BtnCalculation_Machine_time_byMachineType(End)`), `Sp_MachineSpeedanalysis_2_new`, `Sp_Manufacture_SetTime_BB`, `Sp_Manufacture_SetTimeDivRow`, MES event-report procs, and the unified-planning recalc family.
