Is it possible to have a date in a field in a db called entry date, and a field called finish date, the entry date will be pre populated but i want the finish date to be 21 days later, is there a method to be able to do this?
Thanks
You appear to be using Microsoft Access. The finish date field (column) can be updated in the After Update event of a start date control on a form, or you can create a query that updates the field, or since Access 2010, you can use a data macro. However, if the date is always 21 days in advance of the start date, do you need a field (column) at all? A query will allow you to show the end date easily enough:
SELECT StartDate, StartDate + 21 As EndDate
FROM MyTable
In opposite of Excel that directly you can add to date There is Function to add day or month or year to Date in Access.
Exmaples:
DateAdd('d', 130 , Date)
DateAdd('d', 430 , FirstDate) //add month and year by calculating extra days
DateAdd('m',3 , Date)
DateAdd('y', 2 , Date)
Related
Trying to get records where a date in a datetime field is not within the current month and year.
I add the current date when an email is sent to the nl_last_sent field.
The script runs daily (emails a monthly newsletter) and I don't want to re-send the email to recipients that have already received it.
Since people can opt-in at any time during the month, I still want them to receive it during the current month, which is why I run it daily.
So if the value of nl_last_sent is 2019-03-07 8:55:10, they have already received the March 2019 newsletter.
And when I run again, I do not want that record included.
Testing with any date in 2019-03.. does not select the record. Correct.
I tested the code below, changing nl_last_sent to 2019-01-01 11:15:56, which should select the record since the year and month in the field do not match the current year and month, but no errors and no records returned.
... WHERE
( YEAR(nl_last_sent) != YEAR(CURRENT_DATE())
AND MONTH(nl_last_sent) != MONTH(CURRENT_DATE()) )
Any suggestions?
#Raymond Nijland I will provide an MCVE next time, thanks!
Using a modified version of code from #Raymond Nijland , I was able to correct. Thanks for the assistance.
Final working code:
BETWEEN ( LAST_DAY(CURRENT_DATE() ) + INTERVAL 1 DAY ) - INTERVAL 1 MONTH AND
LAST_DAY(CURRENT_DATE() )
I have a database table that has fields as such :
TIME(Datetime) Update_ID
2013-11-25 05:00:14 XC3
2013-11-25 06:00:13 XC4
2013-11-25 06:00:19 XC5
2013-12-25 23:00:14 XC6
2013-12-25 24:00:00 XC7
So assuming i want to find a trend on the updates to know which period of the day has the a particular number of updates, what i initially think of is doing something like this :
SELECT COUNT(TIME) FROM table WHERE TIME between '06:00:00' and '12:00:00'
But this doesn't work because i think since the date is not added with the time, a default value for date is added(some date around 1970). If, i add the beginning and enddate in my query, i am afraid it won't give me the results i need.
Use
WHERE HOUR(TIME)...GROUP BY DAY(TIME)
in case you have more than 1 day
You are correct, the problem is that when you do not specify the date, a default one is added.
You can use the EXTRACT function to extract the time from a date, like this:
SELECT COUNT(*)
FROM mytable
WHERE EXTRACT(HOUR_SECOND from TIME) between 60000 and 120000
Note that the time portion in the condition is specified in a different format - i.e. as numbers, without colons and quotes.
Demo on SqlFiddle.
Suppose I have a MySQL table called birthday with dob as a column. dob has lot of dates in date time format. I have a perl variable $test=current date. My problem here is, how can I get the all the values present in the dob column that matches with the day and month of $test.
Let us assume, $test='2013-05-28 00:00:00' So, now I dont know how to write a query to select all the entries in MySQL table which matches the day and month of the $test i.e 28 and 5 respectively.
You need to use Month and Day function inside mysql query like
select * from birthday where Day(dob) = Day('2013-05-28 00:00:00')
and Month(dob) = Month('2013-05-28 00:00:00');
Hope it works.
I have a field in my table called created_date. The date format is 2010-02-28. I just wondering is it possible to do a mysql statement, only return the day instead of the entire date. eg. 28
SELECT
day(created_date)
FROM
table
This above query throw me error, is there a way i can do similar stuff?
cheers
Use MySQL built-in function called DAYOFMONTH
mysql> SELECT DAYOFMONTH('2007-02-03');
-> 3
DAYOFMONTH()
From Docs,
Returns the day of the month for date, in the range 1 to 31, or 0 for
dates such as '0000-00-00' or '2008-00-00' that have a zero day part.
MySql EXTRACT function extracts day, month or year from a given date.
select extract(day from created_date) as created_day from table
you can fetch the whole date in your format and display only the required field that is date by using this
date("j", strtotime(date('Y-m-d')) );
[MySQL/PHP] My table has a date column of datetime format. All records are of the YYYY-MM-DD HH:MM:SS variety.
MySQL queries like SELECT record FROM table WHERE date > '1941' AND date < '1945' work nicely.
MySQL queries like SELECT record FROM table WHERE date > '1941-03-01' AND date < '1945-01-30' also work nicely.
But what about if I wanted all records that were filed in March, regardless of year? Or all records filed on the 17th, regardless of month/year?
``SELECT record FROM table WHERE date = '03'` clearly doesn't work.
I know I could snag it with a LIKE '%-03-%' parameter, but that doesn't leave room for me to search for range, like all records from March to May.
Help? :-)
Try WHERE MONTH(DATE(`date`)) BETWEEN '03' AND '05'
The DATE() part is to extract the date from the timestamp to be used with MONTH().
You can use MySQL date functions:
SELECT record FROM table WHERE MONTH(date) = 3
SELECT record FROM table WHERE DAY(date) = 17
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
If you look at http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html, you will find many useful functions for your purpose.
... WHERE MONTH(date) = 3, e.g. =)