|
-
Dec 5th, 2007, 11:46 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Date$
how do I get the current date from the computer?
-
Dec 5th, 2007, 11:48 AM
#2
Re: Date$
One way...
MessageBox.Show(My.Computer.Clock.LocalTime.ToShortDateString)
Another way...
MessageBox.Show(System.DateTime.Today.ToShortDateString)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 11:50 AM
#3
Thread Starter
Fanatic Member
Re: Date$
Thanks!!!
one related question, if the computers date format is changed, will it change
the formated date from this function?
-
Dec 5th, 2007, 11:51 AM
#4
Re: [RESOLVED] Date$
It will eval to whatever the systems regional date/time settings are.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 11:51 AM
#5
Re: [RESOLVED] Date$
Yes it will. That function just grabs whatever is there.
-
Dec 5th, 2007, 11:52 AM
#6
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
ok. is there anyway to get the same format no matter what the computer is set to?
-
Dec 5th, 2007, 11:53 AM
#7
Re: [RESOLVED] Date$
You could, however, try something like this if you require a specific format
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = DateTime.Now.ToString("MM/dd/yyyy")
End Sub
-
Dec 5th, 2007, 11:53 AM
#8
Re: [RESOLVED] Date$
You can specify the format if you are worried that the system may use some different format then what you need to calculate with or ??
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 11:54 AM
#9
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
I am working on a database and I want to add the year to a new record when it is created.
-
Dec 5th, 2007, 11:56 AM
#10
Re: [RESOLVED] Date$
Then your tables field's data type should be Date/Time.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 12:00 PM
#11
Re: [RESOLVED] Date$
Actually, I prefer storing dates as straight text, although I've discovered few agree with me. 
Anyway, to retrieve the date, use
vb.net Code:
DateTime.Today.Year.ToString
-
Dec 5th, 2007, 12:02 PM
#12
Re: [RESOLVED] Date$
Yes, I disagree 
Also, you mean to retrieve the Year
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 12:03 PM
#13
Re: [RESOLVED] Date$
Give me text or give me death! 
My code snippet does return the current year.
-
Dec 5th, 2007, 12:08 PM
#14
Re: [RESOLVED] Date$
 Originally Posted by Hack
Anyway, to retrieve the date, use
. .
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 12:10 PM
#15
Re: [RESOLVED] Date$
Oh piffle.....he knew what I meant.
-
Dec 5th, 2007, 12:11 PM
#16
Re: [RESOLVED] Date$

Can you read my mind too 
Ps, I got the last word in
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 12:12 PM
#17
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
the length will change.
12/5/2007
1/1/2007
12/12/2007
is string handling the only way to get the year, month, day??
-
Dec 5th, 2007, 12:14 PM
#18
Re: [RESOLVED] Date$
Not really. You should just use each function to parse out what you need.
DateTime.Today.Month.ToString()
DateTime.Today.Day.ToString()
DateTime.Today.Year.ToString()
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 5th, 2007, 12:14 PM
#19
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
ok, i got it now.
thanks!!!!!!!!!!!!!
-
Dec 5th, 2007, 12:48 PM
#20
Re: [RESOLVED] Date$
If you want the whole date, and not just the year, then wouldn't this work for you?
 Originally Posted by Hack in Post # 7
You could, however, try something like this if you require a specific format
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = DateTime.Now.ToString("MM/dd/yyyy")
End Sub
-
Dec 5th, 2007, 12:50 PM
#21
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
yes, I will make an note of that.
this turns out to be what I need:
DateTime.Today.Month.ToString()
DateTime.Today.Day.ToString()
DateTime.Today.Year.ToString()
-
Dec 5th, 2007, 12:52 PM
#22
Re: [RESOLVED] Date$
Just one final thing. I have seen this way too many times. If you are going to be storing the date, or the year, or something along those lines in DB fields, do you call the fields Year or Date or the like. Those are reserved words and should not be used for field names.
-
Dec 5th, 2007, 12:54 PM
#23
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
I am using: "IncidentYear"
-
Dec 5th, 2007, 12:56 PM
#24
Re: [RESOLVED] Date$
Outstanding. You, potentially, have saved yourself headaches when running queries against your tables.
-
Dec 5th, 2007, 12:56 PM
#25
Thread Starter
Fanatic Member
Re: [RESOLVED] Date$
Yes
no confusion this way
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|