473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get yesterday date

Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is
there a similar way to do it in vb.Net?

Thanks in advance
Nov 21 '05 #1
4 57867
May be work with
Now().AddDays(-1)

"Li Pang" wrote:
Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is
there a similar way to do it in vb.Net?

Thanks in advance

Nov 21 '05 #2
Hi Li Pang,

You can use the following code:

Dim oTimeSpan As New System.TimeSpan (1,0,0,0)
Dim oDate As System.DateTime = System.DateTime .Now.Substract( oTimeSpan)

and oDate should contain yesterdays date...

Greetings,

Juan Pedro Gonzalez


"Li Pang" <Li****@discuss ions.microsoft. com> escribió en el mensaje
news:96******** *************** ***********@mic rosoft.com...
Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is there a similar way to do it in vb.Net?

Thanks in advance

Nov 21 '05 #3
Li Pang,

You mean this?
Dim yesterday As DateTime = Now.AddDays(-1)

I hope this helps,

Cor
Nov 21 '05 #4


Li Pang wrote:
Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is
there a similar way to do it in vb.Net?

Thanks in advance


As others have posted, Now.AddDays(-1) is the literal translation of
the VB6 expression Now() - 1.

But if you want *yesterday*, rather than *this time yesterday*, you
should be using Today, not Now.

--
Larry Lard
Replies to group please

Nov 21 '05 #5

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

Similar topics

4
4552
by: necromancer_stupidspambot | last post by:
Hi, I am trying to find a simple way to get "yesterday's" date. I know I can build various check to seee if we are in leap year, if we are the 1st then yesterday is the 31(or 30 depending of the month) etc. but there is got to be a simpler way than that. I was thinking of using the gmtime (field 7 as you can see int the code)then substract one, then use strptime to rebuild the time but it doesn't work(probably because I misunderstood...
3
3396
by: Darren | last post by:
Hello, How would I write in SQL or ASP the following?: Count number of Database Records between NOW and 24 HOURS EARLIER? I know how to retrieve recordsets etc - its just the date thing I cant grasp. I am stuck getting the 24 hours earlier data capture. Thanks! Gary.
4
10107
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
15
3881
by: Paul J. Ettl | last post by:
Two questions: I use var date1 = new Date(); to get todays date. But how can I get yesterdays date? Furthermore I use
8
2914
by: Anonmyous | last post by:
Hello, how can I get the yesterdays date? Thanks for any suggestions and tips.
1
2856
by: Joris De Groote | last post by:
Hi How can I easily make a date object that has the date in it of yesterday? (yesterdag of the date the program runs ;) ). Thanks
10
4021
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format readable to visitors the one and only solution (e.g. strtotime() + date() OR DateTime object)? Perhaps,...
18
4987
Jerry Maiapu
by: Jerry Maiapu | last post by:
I am trying to create a simple clock in clock out (timesheet) in ms access. I have two tables (tblnames for staff names and tbldates for clocking times). tblnames has 2 fields namely id=autonumber,names =text. and tbldates has 4 fiels Id=autonumber,namesid=number, clockin=time/date and clock out =date/time. the twos have a one to many relationship I have a form that has a combo box that holds names of employees. in the same form i have a...
6
3140
by: ziycon | last post by:
I have a script that outputs 'Today' or 'Yesterday' for the date a piece of content was posted but if its the first of the month yesterday don't work. Is there a way to subtract one day from the date variable, the below code I'm using at the moment is: if(date("dmY") == date("dmY", strtotime($datetimeIn))) $datetime = 'Today @ '.date("H:i", strtotime($datetimeIn)); else if((date("d")-1).date("mY") == date("dmY",...
0
8674
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
8603
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
9157
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
9027
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
8895
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
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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...
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.