# `FUN_GET_DATE_BC_STARTDATE_NOW` (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_NOW`'`._

## Narrative

**Business context:** Day-shift overflow normalizer used to compute the planning end timestamp from a job's start time. For a day-shift machine (`sWorkType=1`), pushes the timestamp to the next clock-off boundary minus the off-shift window length, so a job that ends after the shift "wraps" to the equivalent point on the following shift. Companion to [`FUN_GET_DATE_BC_STARTDATE`](FUN_GET_DATE_BC_STARTDATE.md), with a leading-comment block preserving the older simpler version.

**What it does:** for `sWorkType=1`, classifies whether `p_Date` falls inside the off-shift window (`sWorkOff` → `sShiftsWork` on the same day). If it does (`p_sWorkTypeValue=2`), computes a new candidate `p_DateRet` at the appropriate `sWorkOff` boundary (same day if `p_Date < today_sWorkOff`, else tomorrow's). Then subtracts the off-shift span (`24*60 - working span`) from the running diff and applies it. Returns the shifted timestamp.

**Invocation:** called by `Sp_BtnCalculation_Machine_time_byMachineTypeEnd` (the end-time recalc twin of `Sp_BtnCalculation_Machine_time_byMachineType`). Production-scheduling chain.
