Todays date plus Time that is typed

  • Thread starter Thread starter Gerry Viator
  • Start date Start date
G

Gerry Viator

Hi all,

I have a textbox were a time is typed in like: upto 4 numbers

1900
300
1000
1425

I would like as they type the text to show todays date plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry
 
If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach
 
Thanks for your help,

The number is adding. I'm sorry for not being clear.

I want to replace the minutes with the time corsponding to the 4 or 3
numbers.

like if the current time is 8/12/2003 1:02:48 PM

and the user typed in this 325PM would change to 8/12/2003 3:25:00 PM

the user will be able to type in either 3 or 4 numbers and ending in am or
pm

thanks
Gerry



Tu-Thach said:
If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach
-----Original Message-----
Hi all,

I have a textbox were a time is typed in like: upto 4 numbers

1900
300
1000
1425

I would like as they type the text to show todays date plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry




.
 
Hi Gerry,

Here is a simple demo for you. You may need to realize your own algorithm
to validate user's input. You may create a new VB.NET windows project and
add two textboxes and a button on to the form. Here is the code of
Button1_Click.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim str As String = TextBox1.Text
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
End If
str3 = str.Substring(str.Length - 2, 2)
' Mod is a operation, for example, 13 mod 12 = 1, 24
mod 12 =0 and so.
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1) Mod 12, CInt(str2) Mod 60, dt.Second)

TextBox2.Text = ddt.ToString() + UCase(str3)

End Sub

Please try the code above and let me know if this is what you want!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Tue, 12 Aug 2003 13:19:47 -0400
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104327
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

The number is adding. I'm sorry for not being clear.

I want to replace the minutes with the time corsponding to the 4 or 3
numbers.

like if the current time is 8/12/2003 1:02:48 PM

and the user typed in this 325PM would change to 8/12/2003 3:25:00 PM

the user will be able to type in either 3 or 4 numbers and ending in am or
pm

thanks
Gerry



Tu-Thach said:
If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach
-----Original Message-----
Hi all,

I have a textbox were a time is typed in like: upto 4 numbers

1900
300
1000
1425

I would like as they type the text to show todays date plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry




.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks for your help,

It adds at the end AMPM

just need one or the other based on the time they type

325pm would be PM
1650pm would be PM
1000am would be AM

but should catch if
the user types in

1600am should give error or just ask to correct.

thanks
Gerry

Peter Huang said:
Hi Gerry,

Here is a simple demo for you. You may need to realize your own algorithm
to validate user's input. You may create a new VB.NET windows project and
add two textboxes and a button on to the form. Here is the code of
Button1_Click.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim str As String = TextBox1.Text
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
End If
str3 = str.Substring(str.Length - 2, 2)
' Mod is a operation, for example, 13 mod 12 = 1, 24
mod 12 =0 and so.
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1) Mod 12, CInt(str2) Mod 60, dt.Second)

TextBox2.Text = ddt.ToString() + UCase(str3)

End Sub

Please try the code above and let me know if this is what you want!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Tue, 12 Aug 2003 13:19:47 -0400
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104327
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

The number is adding. I'm sorry for not being clear.

I want to replace the minutes with the time corsponding to the 4 or 3
numbers.

like if the current time is 8/12/2003 1:02:48 PM

and the user typed in this 325PM would change to 8/12/2003 3:25:00 PM

the user will be able to type in either 3 or 4 numbers and ending in am or
pm

thanks
Gerry



Tu-Thach said:
If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach

-----Original Message-----
Hi all,

I have a textbox were a time is typed in like: upto 4
numbers

1900
300
1000
1425

I would like as they type the text to show todays date
plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry




.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Gerry,

I have written a sample, please check if it is what you want.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = ""
TextBox1.MaxLength = 6
TextBox2.Text = ""
TextBox2.MaxLength = 6
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim str As String = TextBox1.Text
If str.Length < 5 Then
MsgBox("Please input somewhat like 1200PM format")
Exit Sub
End If
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
str3 = str.Substring(str.Length - 2, 2)
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
If Not (Char.IsNumber(str1, 0) And Char.IsNumber(str1, 1) _
And Char.IsNumber(str2, 0) And Char.IsNumber(str2, 1) _
And (UCase(str3) = "PM" Or UCase(str3) = "AM")) Then
MsgBox("Please input somewhat like 1100PM format")
Exit Sub
End If
If CInt(str1) < 0 Or CInt(str1) > 11 Then
MsgBox("Please enter the hours between 0-11")
Exit Sub
End If
If CInt(str2) < 0 Or CInt(str2) > 59 Then
MsgBox("Please enter the hours between 0-59")
Exit Sub
End If
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
If Not (Char.IsNumber(str1, 0) _
And Char.IsNumber(str2, 0) And Char.IsNumber(str2, 1) _
And (UCase(str3) = "PM" Or UCase(str3) = "AM")) _
Then
MsgBox("Please input somewhat like 500PM format")
Exit Sub
End If
If CInt(str1) < 0 Or CInt(str1) > 11 Then
MsgBox("Please enter the hours between 0-11")
Exit Sub
End If
If CInt(str2) < 0 Or CInt(str2) > 59 Then
MsgBox("Please enter the hours between 0-59")
Exit Sub
End If
End If
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1), CInt(str2), dt.Second)
TextBox2.Text = ddt.ToString() + UCase(str3)
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
<[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Wed, 13 Aug 2003 11:01:11 -0400
Lines: 150
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104410
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

It adds at the end AMPM

just need one or the other based on the time they type

325pm would be PM
1650pm would be PM
1000am would be AM

but should catch if
the user types in

1600am should give error or just ask to correct.

thanks
Gerry

Peter Huang said:
Hi Gerry,

Here is a simple demo for you. You may need to realize your own algorithm
to validate user's input. You may create a new VB.NET windows project and
add two textboxes and a button on to the form. Here is the code of
Button1_Click.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim str As String = TextBox1.Text
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
End If
str3 = str.Substring(str.Length - 2, 2)
' Mod is a operation, for example, 13 mod 12 = 1, 24
mod 12 =0 and so.
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1) Mod 12, CInt(str2) Mod 60, dt.Second)

TextBox2.Text = ddt.ToString() + UCase(str3)

End Sub

Please try the code above and let me know if this is what you want!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Tue, 12 Aug 2003 13:19:47 -0400
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104327
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

The number is adding. I'm sorry for not being clear.

I want to replace the minutes with the time corsponding to the 4 or 3
numbers.

like if the current time is 8/12/2003 1:02:48 PM

and the user typed in this 325PM would change to 8/12/2003 3:25:00 PM

the user will be able to type in either 3 or 4 numbers and ending in am or
pm

thanks
Gerry



If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach

-----Original Message-----
Hi all,

I have a textbox were a time is typed in like: upto 4
numbers

1900
300
1000
1425

I would like as they type the text to show todays date
plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry




.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks again for your help,

but the same thing keeps coming up like this when you type in 325pm

8/14/2003 3:25:22 AMPM

thanks
Gerry



Peter Huang said:
Hi Gerry,

I have written a sample, please check if it is what you want.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = ""
TextBox1.MaxLength = 6
TextBox2.Text = ""
TextBox2.MaxLength = 6
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim str As String = TextBox1.Text
If str.Length < 5 Then
MsgBox("Please input somewhat like 1200PM format")
Exit Sub
End If
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
str3 = str.Substring(str.Length - 2, 2)
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
If Not (Char.IsNumber(str1, 0) And Char.IsNumber(str1, 1) _
And Char.IsNumber(str2, 0) And Char.IsNumber(str2, 1) _
And (UCase(str3) = "PM" Or UCase(str3) = "AM")) Then
MsgBox("Please input somewhat like 1100PM format")
Exit Sub
End If
If CInt(str1) < 0 Or CInt(str1) > 11 Then
MsgBox("Please enter the hours between 0-11")
Exit Sub
End If
If CInt(str2) < 0 Or CInt(str2) > 59 Then
MsgBox("Please enter the hours between 0-59")
Exit Sub
End If
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
If Not (Char.IsNumber(str1, 0) _
And Char.IsNumber(str2, 0) And Char.IsNumber(str2, 1) _
And (UCase(str3) = "PM" Or UCase(str3) = "AM")) _
Then
MsgBox("Please input somewhat like 500PM format")
Exit Sub
End If
If CInt(str1) < 0 Or CInt(str1) > 11 Then
MsgBox("Please enter the hours between 0-11")
Exit Sub
End If
If CInt(str2) < 0 Or CInt(str2) > 59 Then
MsgBox("Please enter the hours between 0-59")
Exit Sub
End If
End If
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1), CInt(str2), dt.Second)
TextBox2.Text = ddt.ToString() + UCase(str3)
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
<[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Wed, 13 Aug 2003 11:01:11 -0400
Lines: 150
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104410
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

It adds at the end AMPM

just need one or the other based on the time they type

325pm would be PM
1650pm would be PM
1000am would be AM

but should catch if
the user types in

1600am should give error or just ask to correct.

thanks
Gerry

Peter Huang said:
Hi Gerry,

Here is a simple demo for you. You may need to realize your own algorithm
to validate user's input. You may create a new VB.NET windows project and
add two textboxes and a button on to the form. Here is the code of
Button1_Click.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim str As String = TextBox1.Text
Dim dt As DateTime
dt = Now
Dim str1, str2, str3 As String
If str.Length = 6 Then
str1 = str.Substring(0, 2)
str2 = str.Substring(2, 2)
ElseIf str.Length = 5 Then
str1 = str.Substring(0, 1)
str2 = str.Substring(1, 2)
End If
str3 = str.Substring(str.Length - 2, 2)
' Mod is a operation, for example, 13 mod 12 = 1, 24
mod 12 =0 and so.
Dim ddt As New System.DateTime(dt.Year, dt.Month, dt.Day,
CInt(str1) Mod 12, CInt(str2) Mod 60, dt.Second)

TextBox2.Text = ddt.ToString() + UCase(str3)

End Sub

Please try the code above and let me know if this is what you want!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Gerry Viator" <[email protected]>
References: <#$m#[email protected]>
<[email protected]>
Subject: Re: Todays date plus Time that is typed
Date: Tue, 12 Aug 2003 13:19:47 -0400
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: viatorg.gi.musc.edu 128.23.252.142
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:104327
X-Tomcat-NG: microsoft.public.dotnet.general

Thanks for your help,

The number is adding. I'm sorry for not being clear.

I want to replace the minutes with the time corsponding to the 4 or 3
numbers.

like if the current time is 8/12/2003 1:02:48 PM

and the user typed in this 325PM would change to 8/12/2003 3:25:00 PM

the user will be able to type in either 3 or 4 numbers and ending in
am
or
pm

thanks
Gerry



If the time for the textbox is in seconds, then you can
call DateTime.Now.AddSeconds([the parsed value from
textbox]).

Tu-Thach

-----Original Message-----
Hi all,

I have a textbox were a time is typed in like: upto 4
numbers

1900
300
1000
1425

I would like as they type the text to show todays date
plus the time they
type.
seconds can just be 00.

8/12/2003 11:38:40 AM

I know I can do this to get today's date and time

txtboxstarttime.Text = Date.Now



thanks

Gerry




.






Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top