{"id":9198,"date":"2024-09-24T06:57:12","date_gmt":"2024-09-24T06:57:12","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9198"},"modified":"2024-09-24T08:35:21","modified_gmt":"2024-09-24T08:35:21","slug":"add-time-field-in-odoo-15-models-database-simple-guide","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/add-time-field-in-odoo-15-models-database-simple-guide\/","title":{"rendered":"Add Time Field in Odoo 15 Models Database \u2013 Simple Guide"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,834<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>In Odoo 15, if you want to add a <strong>Time<\/strong> field to a model in the database, you can use the <code>fields.Float<\/code> or <code>fields.Datetime<\/code> type depending on whether you need to store just the time or both the date and time.<\/p>\n\n\n\n<p>Here&#8217;s how to do it:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Using <code>fields.Float<\/code> for Time Only:<\/h3>\n\n\n\n<p>If you want to store just the time in hours (e.g., 10.5 for 10:30 AM), you can use a <code>Float<\/code> field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from odoo import models, fields\n\nclass YourModel(models.Model):\n    _name = 'your.model.name'\n\n    time_field = fields.Float(string='Time (in hours)')<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Using <code>fields.Datetime<\/code> for Date and Time:<\/h3>\n\n\n\n<p>If you want to store both the date and time, you can use <code>fields.Datetime<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from odoo import models, fields\n\nclass YourModel(models.Model):\n    _name = 'your.model.name'\n\n    datetime_field = fields.Datetime(string='Date and Time')<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Using <code>fields.Float<\/code> and Time Widgets in Views:<\/h3>\n\n\n\n<p>You can also use widgets in Odoo views to display the time more clearly.<\/p>\n\n\n\n<p>In your XML view file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;field name=\"time_field\" widget=\"float_time\"\/&gt;<\/code><\/pre>\n\n\n\n<p>This widget will allow you to input and display the time in hours and minutes (e.g., 2.5 hours as 02:30).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Using <code>fields.Time<\/code> for Time Only (Community modules may be required):<\/h3>\n\n\n\n<p>If you need a dedicated <code>fields.Time<\/code> field to store only the time (without the date), this field type isn&#8217;t natively available in Odoo 15. You may need a custom module or third-party apps for such specific use cases.<\/p>\n\n\n\n<p>This is how you can add a time field depending on your needs!<\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>In the case of Odoo 15, if you eagerly want to add a\u00a0field named Time to a specific model in the created database, you can simply utilize the fields. Datetime or fields. Float type according to you on whether you want to store only time or both time and date while having <a href=\"https:\/\/www.infinitivehost.com\/managed-odoo-server-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>odoo server solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,834 Views In Odoo 15, if you want to add a Time field to a model in the database, you can use the fields.Float or fields.Datetime type depending on whether you need to store just the time or both the date and time. Here&#8217;s how to do it: 1. Using fields.Float for Time Only: If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[203],"tags":[],"class_list":["post-9198","post","type-post","status-publish","format-standard","hentry","category-odoo"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9198"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9198\/revisions"}],"predecessor-version":[{"id":9205,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9198\/revisions\/9205"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}