
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tips and tricks Archives - TECHNIG</title>
	<atom:link href="https://www.technig.com/tag/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.technig.com/tag/tips-and-tricks/</link>
	<description>Gateway for IT Experts and Tech Geeks</description>
	<lastBuildDate>Mon, 06 Mar 2017 15:34:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://www.technig.com/wp-content/uploads/2020/04/32x32.png</url>
	<title>tips and tricks Archives - TECHNIG</title>
	<link>https://www.technig.com/tag/tips-and-tricks/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">162720667</site>	<item>
		<title>How to Query Posts by Different Dates in Laravel 5</title>
		<link>https://www.technig.com/laravel-5-query-posts-dates/</link>
					<comments>https://www.technig.com/laravel-5-query-posts-dates/#comments</comments>
		
		<dc:creator><![CDATA[Hujatulla Asghari]]></dc:creator>
		<pubDate>Mon, 06 Mar 2017 15:34:48 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[Laravel 5]]></category>
		<category><![CDATA[Laravel Framework]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<guid isPermaLink="false">https://www.technig.com/?p=9088</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1200" height="720" src="https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Laravel 5 query posts by dates" decoding="async" fetchpriority="high" srcset="https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates.jpg 1200w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-300x180.jpg 300w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-768x461.jpg 768w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-1024x614.jpg 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></div>
<p>Laravel 5 is the most popular PHP Framework. Developing php application is easy, fast and enjoyable with Laravel. In this tutorial you will learn Laravel 5 query posts by dates tips and tricks. You will learn how to query today&#8217;s post; how to query this week&#8217;s post and this months posts. This tutorial is going [&#8230;]</p>
<p>The post <a href="https://www.technig.com/laravel-5-query-posts-dates/">How to Query Posts by Different Dates in Laravel 5</a> appeared first on <a href="https://www.technig.com">TECHNIG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1200" height="720" src="https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Laravel 5 query posts by dates" decoding="async" srcset="https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates.jpg 1200w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-300x180.jpg 300w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-768x461.jpg 768w, https://www.technig.com/wp-content/uploads/2017/03/Laravel-5-query-posts-by-dates-1024x614.jpg 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></div><p>Laravel 5 is the most popular PHP Framework. Developing php application is easy, fast and enjoyable with Laravel. In this tutorial you will learn Laravel 5 query posts by dates tips and tricks. You will learn how to query today&#8217;s post; how to query this week&#8217;s post and this months posts. This tutorial is going to short and show you the simple techniques for query posts by different dates.</p>
<h2>Laravel 5 Query Posts by Dates</h2>
<p>Laravel uses Carbon class date and time builder. You can learn more <a href="http://carbon.nesbot.com/docs/">here </a>about Carbon. As we promise to make this tutorial as short as possible, let&#8217;s start coding.</p>
<h3>How to Query Today&#8217;s Posts</h3>
<p>We assume you have a Post model and a created_at field in posts table of your database.</p>
<pre class="theme:sublime-text lang:php decode:true">$today_posts = App\Post::whereRaw('Date(created_at) = CURDATE()')-&gt;get();

</pre>
<h3>How to Query Yesterday&#8217;s Posts</h3>
<pre class="theme:sublime-text lang:php decode:true">$yesterday_posts = App\Post::whereRaw('Date(created_at) = DATE_ADD(CURDATE(), INTERVAL -1 DAY)')-&gt;get();

</pre>
<h3>How to Query this week&#8217;s Posts</h3>
<pre class="theme:sublime-text lang:php decode:true">$weekly_posts = App\Post::whereBetween( 'updated_at', [Carbon::today()-&gt;startOfWeek(), Carbon::today()-&gt;endOfWeek()] )-&gt;get();

</pre>
<h3> How to Query this Month Posts</h3>
<pre class="theme:sublime-text lang:php decode:true">$currentMonth = date('m');
$weekly_posts = App\Post::whereRaw('MONTH(created_at) = ?',[$currentMonth])-&gt;get();

</pre>
<p><strong>You might probably ask;</strong></p>
<blockquote><p><em>Why should I learn Laravel 5 query posts by dates and when can I use it?</em></p></blockquote>
<p>You don&#8217;t need to query posts only. There are many situations where you want to compare today&#8217;s post count with yesterday&#8217;s posts. Or maybe you want to count today&#8217;s sold product and yesterday&#8217;s or this week or current month. So, this technique will be quite helpful in those types of applications.</p>
<h3>How to Count Today&#8217;s Posts</h3>
<p>Here is an small tips for counting today&#8217;s orders and you can use it to count other things as well.</p>
<pre class="lang:default decode:true ">$countTodayOrders = App\Order::whereRaw('Date(created_at) = CURDATE()')-&gt;count();
</pre>
<p>All you need to do is to replace the last get() function with count() function.</p>
<h2>Conclusion</h2>
<p>We hope you have learned something new and use it in your next project to create something cool and inspiring. If you have any questions, feel free to comment it bellow.  We will answer as soon as possible. 🙂</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.technig.com/laravel-5-query-posts-dates/">How to Query Posts by Different Dates in Laravel 5</a> appeared first on <a href="https://www.technig.com">TECHNIG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.technig.com/laravel-5-query-posts-dates/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">9088</post-id>	</item>
	</channel>
</rss>
