{"id":3145,"date":"2015-07-16T08:26:50","date_gmt":"2015-07-16T07:26:50","guid":{"rendered":"https:\/\/abcdr.guyader.pro\/?p=3145"},"modified":"2018-04-08T00:02:06","modified_gmt":"2018-04-07T23:02:06","slug":"comment-arrondir-une-date-en-fonction-de-differentes-unites-ceilling-date-floor-date-round-date","status":"publish","type":"post","link":"https:\/\/thinkr.fr\/abcdr\/comment-arrondir-une-date-en-fonction-de-differentes-unites-ceilling-date-floor-date-round-date\/","title":{"rendered":"Comment arrondir une date en fonction de diff\u00e9rentes unit\u00e9s ? ceilling_date, floor_date, round_date"},"content":{"rendered":"<p>La fonction <b>ceilling_date()<\/b>, du package\u00a0<b>lubridate<\/b>, permet d\u2019arrondir une donn\u00e9e de type \u00ab\u00a0date\u00a0\u00bb \u00e0 la date la plus grande en fonction de diff\u00e9rentes unit\u00e9s\u00a0:<\/p>\n<pre><code>\n\nlibrary(lubridate)\n\n\u00a0\n\nx &lt;- as.POSIXct(\"2009-08-03 12:01:57.23\")\n\n\u00a0\n\nceiling_date(x, \"second\")\n\n[1] \"2009-08-03 12:01:58 CEST\"\n\n#On arrondit \u00e0 la seconde la plus grande\n\n\u00a0\n\nceiling_date(x, \"minute\")\n\n[1] \"2009-08-03 12:02:00 CEST\"\n\n#On arrondit \u00e0 la minute la plus grande\n\n\u00a0\n\nceiling_date(x, \"hour\")\n\n[1] \"2009-08-03 13:00:00 CEST\"\n\n#On arrondit \u00e0 l'heure la plus grande\n\n\u00a0\n\nceiling_date(x, \"day\")\n\n[1] \"2009-08-04 CEST\"\n\n#On arrondit au jour le plus grand\n\n\u00a0\n\nceiling_date(x, \"week\")\n\n[1] \"2009-08-09 CEST\"\n\n\u00a0\n\nceiling_date(x, \"month\")\n\n[1] \"2009-09-01 CEST\"\n\n\u00a0\n\nceiling_date(x, \"year\")\n\n[1] \"2010-01-01 CEST\"\n\n<\/code><\/pre>\n<p>\u00a0<\/p>\n<p>De m\u00eame, la fonction <b>floor_date()<\/b>, permet d\u2019arrondir une date \u00e0 la date la plus petite, et la fonction <b>round_date()<\/b>, permet d\u2019arrondir une date \u00e0 la date la plus proche en fonction de diff\u00e9rentes unit\u00e9s.<\/p>\n<pre><code>\n\nlibrary(lubridate)\n\n\u00a0\n\nx1 &lt;- as.POSIXct(\"2009-08-03 12:01:57.23\")\n\nx2 &lt;- as.POSIXct(\"2009-08-03 12:42:57.23\")\n\n\u00a0\n\nfloor_date(x1, \"hour\")\n\n[1] \"2009-08-03 12:00:00 CEST\"\n\n#On arrondit \u00e0 l'heure la plus petite\n\n\u00a0\n\nround_date(x1, \"hour\")\n\n[1] \"2009-08-03 12:00:00 CEST\"\n\nround_date(x2, \"hour\")\n\n[1] \"2009-08-03 13:00:00 CEST\"<br \/> #On arrondit \u00e0 l'heure la plus proche <br \/> <\/code><\/pre>\n<p>\u00a0 \u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>La fonction ceilling_date(), du package\u00a0lubridate, permet d\u2019arrondir une donn\u00e9e de type \u00ab\u00a0date\u00a0\u00bb \u00e0 la date la plus grande en fonction de diff\u00e9rentes unit\u00e9s\u00a0: library(lubridate) \u00a0 x &lt;- as.POSIXct(\u00ab\u00a02009-08-03 12:01:57.23\u00a0\u00bb) \u00a0 ceiling_date(x, \u00ab\u00a0second\u00a0\u00bb) [1] \u00ab\u00a02009-08-03 12:01:58 CEST\u00a0\u00bb #On arrondit \u00e0 la seconde la plus grande \u00a0 ceiling_date(x, \u00ab\u00a0minute\u00a0\u00bb) [1] \u00ab\u00a02009-08-03 12:02:00 CEST\u00a0\u00bb #On arrondit \u00e0 la minute la plus grande \u00a0 ceiling_date(x, \u00ab\u00a0hour\u00a0\u00bb) [1] \u00ab\u00a02009-08-03 13:00:00 CEST\u00a0\u00bb #On arrondit \u00e0 l&rsquo;heure la plus grande \u00a0 ceiling_date(x, \u00ab\u00a0day\u00a0\u00bb) [1] \u00ab\u00a02009-08-04 CEST\u00a0\u00bb #On arrondit au jour le plus grand \u00a0 ceiling_date(x, \u00ab\u00a0week\u00a0\u00bb) [1] \u00ab\u00a02009-08-09 CEST\u00a0\u00bb \u00a0 ceiling_date(x, \u00ab\u00a0month\u00a0\u00bb) [1] \u00ab\u00a02009-09-01 CEST\u00a0\u00bb \u00a0 ceiling_date(x, \u00ab\u00a0year\u00a0\u00bb) [1] \u00ab\u00a02010-01-01 CEST\u00a0\u00bb \u00a0<a class=\"more-link\" href=\"https:\/\/thinkr.fr\/abcdr\/comment-arrondir-une-date-en-fonction-de-differentes-unites-ceilling-date-floor-date-round-date\/\">Read More &rarr;<\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":{"twitter_399453572_399453572":""},"rop_publish_now_history":[],"rop_publish_now_status":"pending","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8,23],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-helene","4":"post-3145","6":"format-standard","7":"category-fonctions-utiles","8":"category-transformation-de-donnees"},"acf":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p9O7Sx-OJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/comments?post=3145"}],"version-history":[{"count":2,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3145\/revisions"}],"predecessor-version":[{"id":4280,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3145\/revisions\/4280"}],"wp:attachment":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/media?parent=3145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/categories?post=3145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/tags?post=3145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}