473,466 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get Date and format to 1st Day of month

I need to fill a textbox with a date that, based on the current day, is 2
months back - PLUS I need it to reflect the first day of the month

so - I've got :
Dim dNow As DateTime = DateTime.Now.ToShortDateString
Dim NewDate As DateTime
NewDate = dNow.AddMonths(-2)

How do I make it so that the day portion of NewDate is always 1?
Oct 7 '08 #1
2 1440
"Seth Williams" <sm@here.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
How do I make it so that the day portion of NewDate is always 1?
Something like:

Dim NewDate As DateTime = DateTime.Now.AddMonths(-2)
NewDate = New DateTime(NewDate.Year, NewDate.Month, 1)

Not 100% certain of the syntax, as I never go anywhere near VB.NET...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 7 '08 #2
Seth:
Try with this:

Dim dNow As DateTime = DateTime.Now
Dim NewDate As DateTime
NewDate = dNow.AddMonths(-2)
NewDate = NewDate.AddDays((NewDate.Day - 1) * -1)
Gustavo A. Cantero
CEO - Scientia® Soluciones Informáticas
MCP - MCSD - MCTS
http://www.scientia.com.ar
http://www.programandoamedianoche.com
http://foro.scientia.com.ar

-----Mensaje original-----
De: Seth Williams [mailto:sm@here.com]
Expuesto a las: Martes, 07 de Octubre de 2008 04:48 p.m.
Expuesto en: microsoft.public.dotnet.framework.aspnet
Conversación: Get Date and format to 1st Day of month
Asunto: Get Date and format to 1st Day of month

I need to fill a textbox with a date that, based on the current day, is
2
months back - PLUS I need it to reflect the first day of the month

so - I've got :
Dim dNow As DateTime = DateTime.Now.ToShortDateString
Dim NewDate As DateTime
NewDate = dNow.AddMonths(-2)

How do I make it so that the day portion of NewDate is always 1?
Oct 7 '08 #3

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

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
8
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
2
by: Ian | last post by:
I would like to have some validation on a date field. The date format is dd/mm which is used for our financial year end. I suppose I need also consider leap years. Please can you shed some light on...
0
by: UBI | last post by:
Vorrei suggerire una funzione completa per la differenza fra due date. (questo č codice freeware, niente di illegale) La funzione seguente permette il calcolo di una differenza precisa tra due...
1
by: Rotsj | last post by:
Hi, i'm using visual foxpro 9 with a mysql 5 database, for direct access to my database i use navicat. In visual foxpro i've set my date format to dd-mm-yyyy, also i did this in navicat. However...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
4
by: jon.lewis | last post by:
I'm populating an unbound combo on a form as follows: Dim strRowSource As String Dim mydate As Date mydate = #1/1/2000# strRowSource = Format(mydate, "MMM YY") Do Until Format(mydate, "MMM...
2
by: thewilldog | last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD" To convert it into a...
7
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.