# `FUN_GET_DATE_KT` (function)

> 根据传入时间获取时间


- **Type:** FUNCTION
- **Returns:** `varchar(255)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_tCStartTime` | `varchar(200)` |
| 2 | IN | `p_sStartDate` | `varchar(200)` |
| 3 | IN | `p_sEndDate` | `varchar(200)` |

## Body

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

## Narrative

**Business context:** 生产排程 → 生产计划管理 → 生产管理 — cross-midnight (跨天/夜班) rest-period shifter used by the workcenter-scheduling time engine. When `Sp_Manufacture_SetTime*` is walking a job along a machine's working calendar and the next free instant lands inside a night-shift's main rest window (default 23:30–00:30, but the window may span midnight), this function pushes the cursor to the end of that window.

**What it does:** treats `p_sStartDate`/`p_sEndDate` as wall-clock times of a rest window that crosses midnight. It tests whether `p_tCStartTime` falls in the window either on the previous calendar day (start-1d … end-today) or on the current day (start-today … end-tomorrow), and if so returns the corresponding end boundary (today or tomorrow). Otherwise returns `p_tCStartTime` unchanged.

**Invocation:** called from `Sp_Manufacture_SetTimeDivRow`, `Sp_Manufacture_SetTime_BB`, and `Sp_Manufacture_SetTime_process` — only on the `p_sWorkType = '2'` (night shift) branch, paired with the `p_sYxStartDate`/`p_sYxEndDate` (夜休) parameters. Ultimately reached via the Java `BtnCalculationService` "计算排程时间" button (Sp_unifiedPlanning_BtnCalculation / Sp_Manufacture_SetTime path).
