hello
I am using following code to access first and last date of current month StartingDate_ms k.Text = Format$(Date, "dd/mm/yyyy")
EndingDate_msk. Text = Format$(MonthLa stDay(Date), "dd/mm/yyyy")can some one help me how I can find fist and last date of previous month?
chill
farhana
6 24683
hello
I am using following code to access first and last date of current month StartingDate_ms k.Text = Format$(Date, "dd/mm/yyyy")
EndingDate_msk. Text = Format$(MonthLa stDay(Date), "dd/mm/yyyy")can some one help me how I can find fist and last date of previous month?
chill
farhana
First day will be 1
and to get last day - Day(DateSerial(Year(Now), Month(Now), 0))
Below will return last date - DateSerial(Year(Now), Month(Now), 0)
thanks
But last day of previous month worked but first day of previous month didn't.
this is what I get when I use your code.I just formatted it to match my requirments.
StartingDate_ms k.Text = Format$(Day(Dat eSerial(Year(No w), Month(Now), 0)), "dd/mm/yyyy")
30/01/1900 i.e incorrect
EndingDate_msk. Text = Format$(DateSer ial(Year(Now), Month(Now), 0), "dd/mm/yyyy")
31/08/2007 i.e correct
any suggestions.
farhana
thanks
But last day ............... ...... - StartingDate_msk.Text = Format$(Day(DateSerial(Year(Now), Month(Now), 0)), "dd/mm/yyyy")
30/01/1900 i.e incorrect - EndingDate_msk.Text = Format$(DateSerial(Year(Now), Month(Now), 0), "dd/mm/yyyy")
31/08/2007 i.e correct
For Last day of PrevMonth - StartingDate_msk.Text = Format$(DateSerial(Year(Now), Month(DateAdd("M", -1, Now)), 0)), "dd/mm/yyyy")
- LastDateOfPreviousMonth = DateAdd("d", -1, CDate((Month(Now)) & "/01/" & Year(Now)))
-
Dim Yr, Mnth
-
If Month(Now) = 1 Then
-
Yr = Year(Now) - 1
-
Mnth = 12
-
Else
-
Yr = Year(Now)
-
Mnth = Month(Now) - 1
-
End If
-
FirstDateOfPreviousMonth = CDate(Mnth & "/01/" & Year(Now))
Regards
-Shrimant Patel-
&
-Harith Patel-
Nice piece of work, shrimant. However, I feel it's better to use DateSerial as it doesn't depend on your PC using a particular date format. For example PCs in the U.S. and Australia would (probably) return different results for CDate function, because the U.S. has the month first, while Oz has the day first.
I'd recommend the following modification of your routine... - LastDateOfPreviousMonth = DateAdd("d", -1, DateSerial(Year(Now), (Month(Now), 1)
-
FirstDateOfPreviousMonth = DateSerial(Year(LastDateOfPreviousMonth), Month(LastDateOfPreviousMonth), 1)
By the way, I seem to recall that the DateAdd() function can sometimes return unexpected results when using the "d" (day) interval. If so, try using "y" (day of year) instead.
thanks everyone. It solved my problem. I appreciate your help
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Killer |
last post by:
How can i calculate the last day of the previous month?
Help me,please
|
by: Ray via SQLMonster.com |
last post by:
Hi there,
See if you can help me with the following:
I need to write an SQL code that will return me:
The 1st day & the Last day of the Previous Month in the following format
(smalldatetime):
yyyy-mm-dd hh:mi:ss (24h)
|
by: SimonC |
last post by:
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.
So, the penultimate week (Monday to Sunday) and the last week (Monday
to ??)
I'm not sure if it can be done, but all help welcomed.
E.g. I have December and would like to see the last 2 weeks.. So this
doesnt mean the last 15 days. What i mean by this is...
|
by: MLH |
last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
'**************************************************************************
' Accepts a date. Determines month & year of the date. Returns
' the date of the last day of that month (in the same year)
'**************************************************************************
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of...
|
by: brymcguire |
last post by:
Hi,
I have a requirement to design a query that identifies items sold
between two dates. There is a 'SoldDate' datetime field used to
register what date the item was sold.
The query needs to identify all sales between the last day of the
previous month and going back one year.
| |
by: ashore |
last post by:
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>
AS
|
by: drkknightbatman |
last post by:
Hi, I am pretty new to Access 2003 and SQL. I am trying to have a count show up in a query to show specific barcode prefix data between the first and the last day of the previous month. I want to do this for the remaining 5 months so I know I would change the -1 to a -2 ect. Anyways, for some reason this is not working and I get a data mismatch error. Here is what I have typed in SQL using Access 2003.
SELECT...
|
by: guyborn |
last post by:
I have been trying to get data from the database from the of the previous month to the second last week of the current month.I only managed to get data from the previous month to today's date.
your help will be highly appreciated
Regards
Guyborn
|
by: marlberg |
last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc
Language: C#, ASP.NET
Pre-compiled Libraries: Enterprise Library 3.0 full
I have a requirement to implement in and display in C# and ASP.NET a DataGrid with Updatable rows based on a date retrieved from a data table in SQL Server. Below is the design algorithm.
1. Retrieve the Max(rundate) From MyDataTable
2. If the current month -1 = rundate .month from step 1 then
2a. ...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |