473,842 Members | 1,926 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 58043
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
4565
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
3404
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
10118
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
15
3901
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
2918
by: Anonmyous | last post by:
Hello, how can I get the yesterdays date? Thanks for any suggestions and tips.
1
2864
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
4033
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
5003
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
3146
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
9715
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
10940
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
10610
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...
0
9451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7030
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
5695
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...
1
4499
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
4087
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3141
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.