Insert Date into SQL c# - Correct Format

  • Thread starter Thread starter vividpetals
  • Start date Start date
V

vividpetals

Hallo guys,
I am getting bonkers (sorry). i have sql2005express/c#.

I have calender and i get the dates right
DateTime DeployDate = Convert.ToDateTime(Calendar1.SelectedDate);
i tried putting the deployed date as a string and having
Calendar1.SelectedDate.Convert.ToString as well

after this i have a insert string which is giving me all i need.....
String getSYS4Table = "SELECT DISTINCT gdsSITE.SiteID,
gdsSITE.SitePriority, gdsSITE.SiteGroup AS SITEGROUPS, gdsSITE.TimeID,
gdsSITE.ZoneID, gdsSITE.Hours, gdsSITE.SystemID,
gdsAssignedGuardSYS4.ForceNumber, gdsAssignedGuardSYS4.Nationality,
gdsAssignedGuardSYS4.PriorityID, gdsAssignedGuardSYS4.FullName,
gdsAssignedGuardSYS4.SiteGroup FROM gdsSITE INNER JOIN
gdsAssignedGuardSYS4 ON gdsSITE.SiteGroup =
gdsAssignedGuardSYS4.SiteGroup";

all is fine! thats right. mys string works though until the dates is
12. because in mys sql serever i can seach and get dates. WHERE
DeployDate='19/08/2006' it refuses so i need to change the date to be
yyyyMMdd but i have been looking and trying and failing on this part.

i need to enter the DeployDate as yyyyMMdd only that. can someone help
me before the doctors come and collect because iam going nuts.

thanks in advance
 
Hi,

Are you sure that you want to Convert a datatime to a datetime with a
command that is to convert a datetime to a string.
DateTime DeployDate = Convert.ToDateTime(Calendar1.SelectedDate);

This can be
string DeployDate = Calendar1.SelectedDate.ToString("yyyyMMdd");
or any other Idateformatprovider

I hope this helps,

Cor
 
Back
Top