473,789 Members | 2,703 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 #1
10 8364
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.

meltedown 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 ?
Nov 20 '06 #2
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.

meltedown 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
Nov 20 '06 #3
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.

meltedown 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
Nov 20 '06 #4
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.

meltedown 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.
Nov 20 '06 #5

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.

meltedown 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.
This from Azizur Rahman at

http://dev.mysql.com/doc/refman/5.0/...functions.html

To get the first day of the current month:

SELECT ((PERIOD_ADD(EX TRACT(YEAR_MONT H FROM CURDATE()),0)*1 00)+1) as
FirstDayOfTheMo nth;

Nov 20 '06 #6
meltedown 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 ?
select date_sub(YOUR_D ATE_COLUMN, interval day(YOUR_DATE_C OLUMN)-1 day)
from YOUR_TABLE;

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 20 '06 #7
"meltedown" <as**@fake.comw rote in message
news:6k******** *********@fe03. news.easynews.c om...
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.

meltedown 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
Well the answer was already given in petersprc's first post, you just need a
little part of it:

date('Y-m-01', strtotime($str) ); // this takes given timestamp $str and
outputs a Y-m-d formatted date for first of the month just as you wanted.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi. net | rot13(xv***@bhg byrzcv.arg)
Nov 20 '06 #8
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.

meltedown 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.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 20 '06 #9
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.
>
meltedown 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++
Nov 21 '06 #10

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

Similar topics

11
22475
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
9629
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
10825
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
3136
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
10236
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
39345
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
4232
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
9511
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
10410
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
10200
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
10139
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,...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
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...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.