473,803 Members | 3,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

first day of month from sql date.

If I have an sql date, such as "2006-11-19" is there a way using either
sql or php date and time functions to get the date of the the first day
of the month ?
Nov 20 '06
10 8367
meltedown wrote:
Jerry Stuckle wrote:
>meltedown wrote:
>>petersprc wrote:

You could work on the text:

$date = '2006-11-19';
$newDate = substr($date, 0, strrpos($date, '-')) . '-01';

meltedown wrote:

petersprc wrote:
>
>You could do something like this:
>>
><?
>>
>function firstDayOfMonth ($str = '2006-11-19')
>{
> $day = date('l', strtotime(date( 'Y/m/01', strtotime($str) )));
> return $day;
>}
>>
>echo firstDayOfMonth ();
>>
>?>
>>
>Change the date format string if you want other information about the
>first day of the month.
>>
>meltedow n wrote:
>>
>>If I have an sql date, such as "2006-11-19" is there a way using
>>either
>>sql or php date and time functions to get the date of the the
>>first day
>>of the month ?
>
>
Thanks, but I want the date, not the weekday. For 2006-11-19 it
would be
2006-11-01


Yes I know but I'd rather not.


Why not? It's probably the most efficient way of doing it.

Could be, and it could be fine, but it treats a date datatype as a
string datatype. I'd rather stick to strict datatypes which to me means
its less likely to have some unforseen problem. I guess its just a
habit I got from starting out with C++
I understand, and that's a very valid reason.

But in PHP there is no date datatype - unless you create a date class
yourself. It's handled as a string.

If you want to be really good about it, you could create a date class
and have it parse out the date from MySQL. I've done this before when
I've needed to do a bunch of stuff on dates. It did help simplify the
rest of the code (which a properly constructed class should do). But it
also added a little extra overhead to the process (which was also expected).

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 21 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
22476
by: Solomon Grundy | last post by:
Select trunc(sysdate,'MM') from dual of course gives me the first day of the month, may I ask what the query is to find the first saturday of the month?
3
9631
by: johkar | last post by:
I need to document.write out a select list populated with the dates for the first and third Wednesday of each month. How do I get to the actual days? <select name="mySelect"> <option value="Oct 1, 2003">Oct 1, 2003</option> <option value="Oct 15, 2003">Oct 15, 2003</option> .....and so on for a continual 12 month period </select> Thanks,
5
10833
by: Parintas Themis STE Kardias | last post by:
Hi How can i have in a textbox the first sunday of a month
4
48221
by: laredotornado | last post by:
Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00". Similarly what function would I use to return the last day of the month? In the above example, the output I would want returned is "3/31/2006 8:00". Thanks, -
18
3137
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is how global variables and function returns work... For example, I have a global array "char datestring;" which is defined in the function speakdate. speakdate just converts a set of integers (date variables) to a string.
44
10239
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
4
39349
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would you place an expression on a query that will convert any given date to the first day of the month...
5
2466
by: tolcis | last post by:
Hi! I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for example). I need to be able to execute it every first of every month for the past 30, 31 or 28 days based on the calendar month. Is there a function or a stored procedure that I can use to do that? Thank you,
6
4233
by: =?Utf-8?B?UGF1bA==?= | last post by:
HI I have a stored procedure that returns data with a date field in the form of a DateTime type. I need to place data in variables based on days of the week starting with the first thursday of the month. So the week would be week 1= (first thursday of the month through the next wed). So for example for July 07 the first thursday is july5th so the first week would be thursday july 5th , friday july 6th, sat july 7th, sun july 8th, mon...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.