# How to convert DateTime to Date in Kotlin

**URL:** <https://discuss.kotlinlang.org/t/how-to-convert-datetime-to-date-in-kotlin/23806>\
**Category:** Support\
**Created:** [December 30, 2021, 10:29am UTC](https://discuss.kotlinlang.org/t/how-to-convert-datetime-to-date-in-kotlin/23806 "2021-12-30T10:29:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![20096057](https://avatars.discourse-cdn.com/v4/letter/2/eb8c5e/32.png) [@20096057](https://discuss.kotlinlang.org/u/20096057)\
**Post date:** [December 30, 2021, 10:29am UTC](https://discuss.kotlinlang.org/t/how-to-convert-datetime-to-date-in-kotlin/23806/1 "2021-12-30T10:29:04Z")

</div>

I have wirtten a base query get some data…

NutritionInTake  
.innerJoin(FoodMaster,{NutritionInTake.foodId},{foodDetails[FoodMaster.id]} )  
.innerJoin(Users,{NutritionInTake.userId},{userDetails[Users.id]} )  
.slice(NutritionInTake.id, Users.name,FoodMaster.foodname, FoodMaster.carbohydrates, FoodMaster.protein, FoodMaster.fat, NutritionInTake.type, NutritionInTake.qty, NutritionInTake.intakedate)  
.select(){( **(NutritionInTake.intakedate ) eq onDate**) and ((NutritionInTake.userId) eq userId) }  
.map{  
allNutritionList.add(mapToNutDetDTO(it))  
}

IntakeDate is a time stamp and OnDate is only date, because of the time, result is not showing properly, Its a web application.

---

<div class="post-metadata">

**Author:** ![Psijic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/psijic/32/2227_2.png) [@Psijic](https://discuss.kotlinlang.org/u/Psijic)\
**Post date:** [November 4, 2022, 11:25am UTC](https://discuss.kotlinlang.org/t/how-to-convert-datetime-to-date-in-kotlin/23806/2 "2022-11-04T11:25:17Z")

</div>

First: it’s better to not to use Java’s default DateTime, there is a topic about it somewhere. LocalDateTime is modern alternative.  
Second: suppose, you need `truncatedTo`  
`val today: LocalDateTime = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS)`
